Skip to content

FIX: preserve non-sympy arguments in func - #525

Open
redeboer wants to merge 4 commits into
mainfrom
issue-524
Open

redeboer wants to merge 4 commits into
mainfrom
issue-524

Conversation

@redeboer

@redeboer redeboer commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Closes #524

🐛 Bug fixes

  • Classes decorated with @unevaluated now override func whenever they have fields declared with argument(sympify=False). Before, SymPy operations that rebuild an expression through expr.func(*expr.args) (replace, rewrite, doit, cse) silently reset these arguments to their defaults. For EnergyDependentWidth with phsp_factor=PhaseSpaceFactorSWave, for example, expr.replace(R, R2) evaluated to a different value than expr.
    • If all non-sympy arguments have their default values, func returns the class itself.
    • Otherwise func returns a subclass that fills in the instance's non-sympy values and constructs an instance of the original class. It compares equal to and hashes like the original class, so checks such as expr.func == BreitWigner, expr.has(expr.func) and expr.find(expr.func) keep working. Rebuilt instances have the original type, so pickling and cache hashes do not change.
  • xreplace now replaces a non-sympy attribute only if the rule has a key of the same type. Previously False matched a key 0 or sympy.Integer(0), and mappings like ParameterValues that accept integer positions could replace such attributes by accident.

❗ Behavioral changes

  • The default str and srepr printers now render non-sympy arguments that differ from their defaults as keyword arguments, for instance MyExpr(0, 3.14, functor=Transformation). This lets parse_expr reconstruct the original expression, given a namespace with the expression class and any classes used as attribute values. Custom printer methods and LaTeX output are unaffected.

Squash commit messages

* BEHAVIOR: print non-default non-sympy arguments in str and srepr
* FIX: match xreplace rules on non-sympy attributes by type

@redeboer redeboer self-assigned this Sep 15, 2026
@redeboer redeboer added the 🐛 Bug Something isn't working label Sep 15, 2026
@redeboer
redeboer added this pull request to stack #526 September 15, 2026 18:10
@redeboer redeboer added this to the 0.16.2 milestone Sep 15, 2026
@redeboer redeboer changed the title FIX: preserve non-sympy arguments when rebuilding expressions FIX: preserve non-sympy arguments in func Sep 15, 2026
@redeboer redeboer added the ❗ Behavior Changes that may affect the framework output label Sep 15, 2026
@redeboer
redeboer marked this pull request as ready for review September 15, 2026 18:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

❗ Behavior Changes that may affect the framework output 🐛 Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rebuilding an @unevaluated expression through func drops its non-sympy arguments

1 participant