Skip to content

Commit

Permalink
Introduces static attribute Operation.unpacked_args_to_init
Browse files Browse the repository at this point in the history
Passing unpacked args is generally helpful if the class derived from
Operation has its constructor implemented as a dataclass.
  • Loading branch information
kaushikcfd committed Oct 22, 2021
1 parent 390b2d3 commit 60eee84
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion matchpy/expressions/expressions.py
Expand Up @@ -280,7 +280,10 @@ def __call__(cls, *operands: Expression, variable_name=None):
return operands[0]

operation = Expression.__new__(cls)
operation.__init__(operands, variable_name=variable_name)
if not cls.unpacked_args_to_init:
operation.__init__(operands, variable_name=variable_name)
else:
operation.__init__(*operands, variable_name=variable_name)

return operation

Expand Down Expand Up @@ -358,6 +361,10 @@ class Operation(Expression, metaclass=_OperationMeta):
infix = False
"""bool: True if the name of the operation should be used as an infix operator by str()."""


unpacked_args_to_init = False
"""bool: True if the class must be instantiated with ``*operands`` instead of ``operands``."""

def __init__(self, operands: List[Expression], variable_name=None) -> None:
"""Create an operation expression.
Expand Down

0 comments on commit 60eee84

Please sign in to comment.