Skip to content

Commit aca7469

Browse files
committed
Drop deprecated auto-self-downcasts
1 parent fad6fcf commit aca7469

3 files changed

Lines changed: 14 additions & 101 deletions

File tree

gen_wrap.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,41 +1468,6 @@ def write_exposer(
14681468
f' isl::handle_isl_error(ctx, "isl_{meth.cls}_read_from_str");'
14691469
'}, py::arg("s"), py::arg("context").none(true)=py::none());\n')
14701470

1471-
# Handle auto-self-downcasts. These are deprecated.
1472-
if not meth.is_static:
1473-
for basic_cls in AUTO_DOWNCASTS.get(meth.cls, []):
1474-
basic_overloads = meth_to_overloads.setdefault((basic_cls, meth.name), [])
1475-
if any(basic_meth
1476-
for basic_meth in basic_overloads
1477-
if (basic_meth.is_static
1478-
or meth.arg_types()[1:] == basic_meth.arg_types()[1:])
1479-
):
1480-
continue
1481-
1482-
# These are high-traffic APIs that are manually implemented
1483-
# and not subject to deprecation.
1484-
if basic_cls == "basic_set":
1485-
if meth.name in ["is_params", "get_hash"]:
1486-
continue
1487-
elif basic_cls == "basic_map" and meth.name in ["get_hash"]:
1488-
continue
1489-
1490-
basic_overloads.append(meth)
1491-
1492-
downcast_doc_str = (f"{doc_str}\n\nDowncast from "
1493-
f":class:`{to_py_class(basic_cls)}` to "
1494-
f":class:`{to_py_class(meth.cls)}`.")
1495-
escaped_doc_str = downcast_doc_str.replace(newline, escaped_newline)
1496-
outf.write(f"// automatic downcast to {meth.cls}\n")
1497-
outf.write(f'wrap_{basic_cls}.def('
1498-
# Do not be tempted to pass 'arg_str' here, it will
1499-
# prevent implicit conversion.
1500-
# https://github.com/wjakob/nanobind/issues/1061
1501-
f'"{py_name}", {func_name}'
1502-
f', py::sig("def {py_name}{type_sig}")'
1503-
f', "{py_name}{type_sig}\\n{escaped_doc_str}"'
1504-
');\n')
1505-
15061471
# }}}
15071472

15081473

islpy/_monkeypatch.py

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -854,14 +854,15 @@ def obj_eq(self: IslObject, other: object) -> bool:
854854
return self.is_equal(other)
855855

856856

857-
def obj_ne(self: object, other: object) -> bool:
858-
return not self.__eq__(other)
857+
def no_eq(_self: IslObject, _other: object) -> bool:
858+
raise TypeError("equality not available; use manual downcast or try plain_is_equal")
859859

860860

861861
for cls in ALL_CLASSES:
862862
if hasattr(cls, "is_equal"):
863863
cls.__eq__ = obj_eq
864-
cls.__ne__ = obj_ne
864+
else:
865+
cls.__eq__ = no_eq
865866

866867

867868
def set_lt(self: _isl.BasicSet | _isl.Set, other: _isl.BasicSet | _isl.Set) -> bool:
@@ -1216,57 +1217,3 @@ def _add_functionality() -> None:
12161217
"Map": "to_map",
12171218
"UnionMap": "to_union_map",
12181219
}
1219-
1220-
1221-
def _depr_downcast_wrapper(
1222-
f: Callable[Concatenate[object, P], ResultT],
1223-
) -> Callable[Concatenate[object, P], ResultT]:
1224-
doc = f.__doc__
1225-
assert doc is not None
1226-
m = _DOWNCAST_RE.search(doc)
1227-
assert m, doc
1228-
basic_cls_name = intern(m.group(1))
1229-
tgt_cls_name = m.group(2)
1230-
1231-
tgt_cls = cast("type", getattr(_isl, tgt_cls_name))
1232-
is_overload = "Overloaded function" in doc
1233-
msg = (f"{basic_cls_name}.{f.__name__} "
1234-
f"with implicit conversion of self to {tgt_cls_name} is deprecated "
1235-
"and will stop working in 2026. "
1236-
f"Explicitly convert to {tgt_cls_name}, "
1237-
f"using .{_TO_METHODS[tgt_cls_name]}().")
1238-
1239-
if is_overload:
1240-
def wrapper(self: object, *args: P.args, **kwargs: P.kwargs) -> ResultT:
1241-
# "Try to" detect bad invocations of, e.g., Set.union, which is
1242-
# an overload of normal union and UnionSet.union.
1243-
if (
1244-
any(isinstance(arg, tgt_cls) for arg in args)
1245-
or
1246-
any(isinstance(arg, tgt_cls) for arg in kwargs.values())
1247-
):
1248-
warn(msg, DeprecationWarning, stacklevel=2)
1249-
1250-
return f(self, *args, **kwargs)
1251-
else:
1252-
def wrapper(self: object, *args: P.args, **kwargs: P.kwargs) -> ResultT:
1253-
warn(msg, DeprecationWarning, stacklevel=2)
1254-
1255-
return f(self, *args, **kwargs)
1256-
update_wrapper(wrapper, f)
1257-
return wrapper
1258-
1259-
1260-
def _monkeypatch_self_downcast_deprecation():
1261-
for cls in ALL_CLASSES:
1262-
for attr_name in dir(cls):
1263-
val = cast("object", getattr(cls, attr_name))
1264-
doc = getattr(val, "__doc__", None)
1265-
if doc and "\nDowncast from " in doc:
1266-
setattr(cls, attr_name, _depr_downcast_wrapper(
1267-
cast("Callable", val), # pyright: ignore[reportMissingTypeArgument]
1268-
))
1269-
1270-
1271-
if not os.environ.get("ISLPY_NO_DOWNCAST_DEPRECATION", None):
1272-
_monkeypatch_self_downcast_deprecation()

test/test_isl.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_upcast():
9696

9797
isl.PwAff(b)
9898

99-
assert b.is_equal(a)
99+
assert b.to_pw_aff().is_equal(a)
100100
assert a.is_equal(b)
101101

102102
s = isl.BasicSet("[n] -> {[i,j,k]: i<=j + k and (exists m: m=j+k) "
@@ -120,7 +120,7 @@ def test_pickling():
120120
inst2 = loads(dumps(inst))
121121

122122
assert inst.space == inst2.space
123-
assert inst.is_equal(inst2)
123+
assert inst.plain_is_equal(inst2)
124124

125125

126126
def test_apostrophes_during_pickling():
@@ -209,7 +209,7 @@ def test_schedule():
209209

210210
def callback(node, build):
211211
schedulemap = build.get_schedule()
212-
accessmap = accesses.apply_domain(schedulemap)
212+
accessmap = accesses.to_union_map().apply_domain(schedulemap)
213213
aff = isl.PwMultiAff.from_map(isl.Map.from_union_map(accessmap))
214214
access = build.call_from_pw_multi_aff(aff)
215215
return isl.AstNode.alloc_user(access)
@@ -361,8 +361,8 @@ def test_align_spaces():
361361
a1_aligned = isl.align_spaces(a1, a2, obj_bigger_ok=True)
362362
a2_aligned = isl.align_spaces(a2, a1)
363363

364-
assert a1_aligned == isl.Aff("[t1, t0, t2] -> { [(32)] }")
365-
assert a2_aligned == isl.Aff("[t1, t0, t2] -> { [(0)] }")
364+
assert a1_aligned.plain_is_equal(isl.Aff("[t1, t0, t2] -> { [(32)] }"))
365+
assert a2_aligned.to_pw_aff().is_equal(isl.PwAff("[t1, t0, t2] -> { [(0)] }"))
366366

367367

368368
def test_pass_numpy_int():
@@ -380,8 +380,8 @@ def test_isl_align_two():
380380
a2 = isl.Aff("[t1, t0] -> { [(0)] }")
381381

382382
a1_aligned, a2_aligned = isl.align_two(a1, a2)
383-
assert a1_aligned == isl.Aff("[t1, t0, t2] -> { [(32)] }")
384-
assert a2_aligned == isl.Aff("[t1, t0, t2] -> { [(0)] }")
383+
assert a1_aligned.plain_is_equal(isl.Aff("[t1, t0, t2] -> { [(32)] }"))
384+
assert a2_aligned.plain_is_equal(isl.Aff("[t1, t0, t2] -> { [(0)] }"))
385385

386386
b1 = isl.BasicSet("[n0, n1, n2] -> { [i0, i1] : }")
387387
b2 = isl.BasicSet("[n0, n2, n1, n3] -> { [i1, i0, i2] : }")
@@ -436,10 +436,11 @@ def test_union_casts():
436436
s1 = isl.UnionSet("{[0]}")
437437
s2 = isl.BasicSet("{[1]}")
438438

439-
s2.union(s1) # works fine
439+
s2u = s2.to_set().to_union_set()
440+
s2u.union(s1) # works fine
440441
s1.union(s2) # did not work while #29 was not fixed
441442

442-
assert s2.union(s1) == s1.union(s2)
443+
assert s2u.union(s1) == s1.union(s2)
443444

444445

445446
def test_remove_map_if_callback():

0 commit comments

Comments
 (0)