Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions gen_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,41 +1468,6 @@ def write_exposer(
f' isl::handle_isl_error(ctx, "isl_{meth.cls}_read_from_str");'
'}, py::arg("s"), py::arg("context").none(true)=py::none());\n')

# Handle auto-self-downcasts. These are deprecated.
if not meth.is_static:
for basic_cls in AUTO_DOWNCASTS.get(meth.cls, []):
basic_overloads = meth_to_overloads.setdefault((basic_cls, meth.name), [])
if any(basic_meth
for basic_meth in basic_overloads
if (basic_meth.is_static
or meth.arg_types()[1:] == basic_meth.arg_types()[1:])
):
continue

# These are high-traffic APIs that are manually implemented
# and not subject to deprecation.
if basic_cls == "basic_set":
if meth.name in ["is_params", "get_hash"]:
continue
elif basic_cls == "basic_map" and meth.name in ["get_hash"]:
continue

basic_overloads.append(meth)

downcast_doc_str = (f"{doc_str}\n\nDowncast from "
f":class:`{to_py_class(basic_cls)}` to "
f":class:`{to_py_class(meth.cls)}`.")
escaped_doc_str = downcast_doc_str.replace(newline, escaped_newline)
outf.write(f"// automatic downcast to {meth.cls}\n")
outf.write(f'wrap_{basic_cls}.def('
# Do not be tempted to pass 'arg_str' here, it will
# prevent implicit conversion.
# https://github.com/wjakob/nanobind/issues/1061
f'"{py_name}", {func_name}'
f', py::sig("def {py_name}{type_sig}")'
f', "{py_name}{type_sig}\\n{escaped_doc_str}"'
');\n')

# }}}


Expand Down
54 changes: 0 additions & 54 deletions islpy/_monkeypatch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os

Check warning on line 1 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Import "os" is not accessed (reportUnusedImport)
import re
from collections.abc import Callable, Collection, Iterable, Mapping, Sequence
from functools import update_wrapper

Check warning on line 4 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Import "update_wrapper" is not accessed (reportUnusedImport)
Expand All @@ -14,7 +14,7 @@
TypeVar,
cast,
)
from warnings import warn

Check warning on line 17 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Import "warn" is not accessed (reportUnusedImport)


if TYPE_CHECKING:
Expand Down Expand Up @@ -595,7 +595,7 @@
:param dimtype: None to get all variables, otherwise
one of :class:`dim_type`.
"""
return self.get_space().get_id_dict(dimtype)

Check warning on line 598 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Return type, "Mapping[Id, tuple[dim_type, int]] | Unknown", is partially unknown (reportUnknownVariableType)

Check warning on line 598 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Type of "get_id_dict" is partially unknown   Type of "get_id_dict" is "((dimtype: dim_type | None = None) -> Mapping[Id, tuple[dim_type, int]]) | Unknown" (reportUnknownMemberType)

Check warning on line 598 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Type of "get_space" is partially unknown   Type of "get_space" is "Unknown | (() -> Space)" (reportUnknownMemberType)


@_memoize_on_first_arg
Expand All @@ -609,7 +609,7 @@
:param dimtype: None to get all variables, otherwise
one of :class:`dim_type`.
"""
return self.get_space().get_var_dict(

Check warning on line 612 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Return type, "Mapping[str, tuple[dim_type, int]] | Unknown", is partially unknown (reportUnknownVariableType)

Check warning on line 612 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Type of "get_var_dict" is partially unknown   Type of "get_var_dict" is "((dimtype: dim_type | None = None, ignore_out: bool = False) -> Mapping[str, tuple[dim_type, int]]) | Unknown" (reportUnknownMemberType)

Check warning on line 612 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Type of "get_space" is partially unknown   Type of "get_space" is "Unknown | (() -> Space)" (reportUnknownMemberType)
dimtype, ignore_out=isinstance(self, EXPR_CLASSES))


Expand All @@ -618,7 +618,7 @@
dimtype: _isl.dim_type
) -> Sequence[str | None]:
"""Return a list of :class:`Id` instances for :class:`dim_type` *dimtype*."""
return [

Check warning on line 621 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Return type, "list[str | Unknown | None]", is partially unknown (reportUnknownVariableType)
self.get_dim_name(dimtype, i)
for i in range(self.dim(dimtype))]

Expand Down Expand Up @@ -869,7 +869,7 @@


def set_le(self: _isl.BasicSet | _isl.Set, other: _isl.BasicSet | _isl.Set) -> bool:
return self.is_subset(other)

Check failure on line 872 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Argument of type "BasicSet | Set" cannot be assigned to parameter "bset2" of type "BasicSet" in function "is_subset"   Type "BasicSet | Set" is not assignable to type "BasicSet"     "Set" is not assignable to "BasicSet" (reportArgumentType)


def set_gt(self: _isl.BasicSet | _isl.Set, other: _isl.BasicSet | _isl.Set) -> bool:
Expand All @@ -877,23 +877,23 @@


def set_ge(self: _isl.BasicSet | _isl.Set, other: _isl.BasicSet | _isl.Set) -> bool:
return other.is_subset(self)

Check failure on line 880 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Argument of type "BasicSet | Set" cannot be assigned to parameter "bset2" of type "BasicSet" in function "is_subset"   Type "BasicSet | Set" is not assignable to type "BasicSet"     "Set" is not assignable to "BasicSet" (reportArgumentType)


def map_lt(self: _isl.BasicMap | _isl.Map, other: _isl.BasicMap | _isl.Map) -> bool:
return self.is_strict_subset(other)

Check failure on line 884 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Argument of type "BasicMap | Map" cannot be assigned to parameter "bmap2" of type "BasicMap" in function "is_strict_subset"   Type "BasicMap | Map" is not assignable to type "BasicMap"     "Map" is not assignable to "BasicMap" (reportArgumentType)


def map_le(self: _isl.BasicMap | _isl.Map, other: _isl.BasicMap | _isl.Map) -> bool:
return self.is_subset(other)

Check failure on line 888 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Argument of type "BasicMap | Map" cannot be assigned to parameter "bmap2" of type "BasicMap" in function "is_subset"   Type "BasicMap | Map" is not assignable to type "BasicMap"     "Map" is not assignable to "BasicMap" (reportArgumentType)


def map_gt(self: _isl.BasicMap | _isl.Map, other: _isl.BasicMap | _isl.Map) -> bool:
return other.is_strict_subset(self)

Check failure on line 892 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Argument of type "BasicMap | Map" cannot be assigned to parameter "bmap2" of type "BasicMap" in function "is_strict_subset"   Type "BasicMap | Map" is not assignable to type "BasicMap"     "Map" is not assignable to "BasicMap" (reportArgumentType)


def map_ge(self: _isl.BasicMap | _isl.Map, other: _isl.BasicMap | _isl.Map) -> bool:
return other.is_subset(self)

Check failure on line 896 in islpy/_monkeypatch.py

View workflow job for this annotation

GitHub Actions / basdedpyright

Argument of type "BasicMap | Map" cannot be assigned to parameter "bmap2" of type "BasicMap" in function "is_subset"   Type "BasicMap | Map" is not assignable to type "BasicMap"     "Map" is not assignable to "BasicMap" (reportArgumentType)


# {{{ project_out_except
Expand Down Expand Up @@ -1216,57 +1216,3 @@
"Map": "to_map",
"UnionMap": "to_union_map",
}


def _depr_downcast_wrapper(
f: Callable[Concatenate[object, P], ResultT],
) -> Callable[Concatenate[object, P], ResultT]:
doc = f.__doc__
assert doc is not None
m = _DOWNCAST_RE.search(doc)
assert m, doc
basic_cls_name = intern(m.group(1))
tgt_cls_name = m.group(2)

tgt_cls = cast("type", getattr(_isl, tgt_cls_name))
is_overload = "Overloaded function" in doc
msg = (f"{basic_cls_name}.{f.__name__} "
f"with implicit conversion of self to {tgt_cls_name} is deprecated "
"and will stop working in 2026. "
f"Explicitly convert to {tgt_cls_name}, "
f"using .{_TO_METHODS[tgt_cls_name]}().")

if is_overload:
def wrapper(self: object, *args: P.args, **kwargs: P.kwargs) -> ResultT:
# "Try to" detect bad invocations of, e.g., Set.union, which is
# an overload of normal union and UnionSet.union.
if (
any(isinstance(arg, tgt_cls) for arg in args)
or
any(isinstance(arg, tgt_cls) for arg in kwargs.values())
):
warn(msg, DeprecationWarning, stacklevel=2)

return f(self, *args, **kwargs)
else:
def wrapper(self: object, *args: P.args, **kwargs: P.kwargs) -> ResultT:
warn(msg, DeprecationWarning, stacklevel=2)

return f(self, *args, **kwargs)
update_wrapper(wrapper, f)
return wrapper


def _monkeypatch_self_downcast_deprecation():
for cls in ALL_CLASSES:
for attr_name in dir(cls):
val = cast("object", getattr(cls, attr_name))
doc = getattr(val, "__doc__", None)
if doc and "\nDowncast from " in doc:
setattr(cls, attr_name, _depr_downcast_wrapper(
cast("Callable", val), # pyright: ignore[reportMissingTypeArgument]
))


if not os.environ.get("ISLPY_NO_DOWNCAST_DEPRECATION", None):
_monkeypatch_self_downcast_deprecation()
Loading