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

ENH: support unevaluated_expression default arguments #376

Merged
merged 4 commits into from
Dec 18, 2023

Conversation

redeboer
Copy link
Member

Default arguments to the instance attributes of an @unevaluated_expresssion() class are now supported. In addition, usage of ClassVar is also better documented on the SymPy helper page.

For instance:

from __future__ import annotations

import sympy as sp
from ampform.sympy import unevaluated_expression
from typing import Any, ClassVar

@unevaluated_expression
class FunkyPower(sp.Expr):
    x: Any
    m: int = 1
    default_return: ClassVar[sp.Expr | None] = None

    def evaluate(self) -> sp.Expr | None:
        if self.default_return is None:
            return self.x**self.m
        return self.default_return


x = sp.Symbol("x")
expr = FunkyPower(x)
assert expr.doit() == x

@redeboer redeboer added the ⚙️ Enhancement Improvements and optimizations of existing features label Dec 18, 2023
@redeboer redeboer self-assigned this Dec 18, 2023
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@redeboer redeboer enabled auto-merge (squash) December 18, 2023 16:12
@redeboer redeboer merged commit 5182dbf into main Dec 18, 2023
19 checks passed
@redeboer redeboer deleted the unevaluated_expression-defaults branch December 18, 2023 16:18
redeboer added a commit that referenced this pull request Dec 22, 2023
* DOC: show ClassVar and default argument use
* ENH: improve local variable names
* ENH: support default arguments for `unevaluated_expression`
* MAINT: write test for `unevaluated_expression` default arguments
@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
⚙️ Enhancement Improvements and optimizations of existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant