Skip to content

Commit

Permalink
Make module level import report warning
Browse files Browse the repository at this point in the history
  • Loading branch information
neNasko1 committed Nov 27, 2024
1 parent 780e22b commit 30401ea
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/spox/_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def not_(self, a: Var) -> Var:


@contextmanager
def operator_overloading(
def _operator_overloading(
op, type_promotion: bool = False, constant_promotion: bool = True
):
"""Enable operator overloading on Var for this block.
Expand Down Expand Up @@ -202,10 +202,6 @@ def operator_overloading(
... return x * y
>>> assert foo()._get_value() == np.array(6)
"""
warnings.warn(
"using operator_overloading is deprecated, consider using https://github.com/Quantco/ndonnx instead",
DeprecationWarning,
)
prev_dispatcher = Var._operator_dispatcher
Var._operator_dispatcher = _NumpyLikeOperatorDispatcher(
op, type_promotion, constant_promotion
Expand All @@ -214,6 +210,17 @@ def operator_overloading(
Var._operator_dispatcher = prev_dispatcher


def __getattr__(name):
if name == "operator_overloading":
warnings.warn(
"using 'operator_overloading' is deprecated, consider using https://github.com/Quantco/ndonnx instead",
DeprecationWarning,
)
return _operator_overloading

raise AttributeError(f"module {__name__} has no attribute {name}")


__all__ = [
# Type warning levels
"TypeWarningLevel",
Expand All @@ -226,5 +233,6 @@ def operator_overloading(
"set_value_prop_backend",
"value_prop_backend",
# Operator overloading on Var
"operator_overloading",
"operator_overloading", # noqa: F822
"__getattr__",
]

0 comments on commit 30401ea

Please sign in to comment.