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

BREAK: rename unevaluated_expression() to unevaluated() #379

Merged
merged 13 commits into from
Dec 21, 2023
Merged

Conversation

redeboer
Copy link
Member

In @unevaluated_expression, the part _expression is redundant, because the class already derives from sympy.Expr. For instance, the following looks more concise and readable with @unevaluated.

>>> @unevaluated
... class MyExpr(sp.Expr):
...     x: sp.Symbol
...     y: sp.Symbol
...     _latex_repr_ = R"z\left({x}, {y}\right)"
...
...     def evaluate(self) -> sp.Expr:
...         x, y = self.args
...         return x**2 + y**2
...
>>> a, b = sp.symbols("a b")
>>> expr = MyExpr(a, b**2)
>>> sp.latex(expr)
'z\\left(a, b^{2}\\right)'
>>> expr.doit()
a**2 + b**4

We will also see in the next PR, which introduces a argument() field specifier.

@redeboer redeboer added the ⚠️ Interface Breaking changes to the API label Dec 21, 2023
@redeboer redeboer self-assigned this Dec 21, 2023
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@redeboer redeboer marked this pull request as ready for review December 21, 2023 14:57
@redeboer redeboer enabled auto-merge (squash) December 21, 2023 15:03
@redeboer redeboer merged commit b76435c into main Dec 21, 2023
21 checks passed
@redeboer redeboer deleted the unevaluated branch December 21, 2023 15:08
redeboer added a commit that referenced this pull request Dec 22, 2023
* BEHAVIOR: do not sympify `str` attributes
* DOC: add docstring to `_get_attribute_values()`
* ENH: implement hash for non-sympy attributes
* ENH: support non-sympy arguments in `@unevaluated()`
* ENH: implement `subs()` method for `unevaluated_expression` classes
* ENH: implement `xreplace()` method for non-sympy attributes
* MAINT: move method implementations to module level
* MAINT: put `TypeVar` definitions under `TYPE_CHECKING`
* MAINT: remove redundant type ignore
* MAINT: test class var definition without `ClassVar`
* MAINT: write test with unsympifiable class
@redeboer redeboer added this to the 0.14.8 milestone Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ Interface Breaking changes to the API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant