Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate operator dispatch in Var #192

Merged
merged 10 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Change log

- Value propagation of string tensors no longer raises an erroneous ``ValueError`` in some instances.

**Pending breaking changes**
cbourjau marked this conversation as resolved.
Show resolved Hide resolved

- Importing :func:`spox._future.operator_overloading`` now triggers a ``DeprecationWarning``. The function will be removed in a future release. Consider using ``ndonnx`` as an alternative.

**Other changes**

- The adaption logic is not using inferred values as initializers anymore.
Expand Down
16 changes: 13 additions & 3 deletions src/spox/_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Module containing experimental Spox features that may be standard in the future."""

import warnings
from collections.abc import Iterable
from contextlib import contextmanager
from typing import Optional, Union
Expand Down Expand Up @@ -164,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 @@ -209,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 @@ -220,6 +232,4 @@ def operator_overloading(
"ValuePropBackend",
"set_value_prop_backend",
"value_prop_backend",
# Operator overloading on Var
"operator_overloading",
]