Skip to content

Commit

Permalink
Some performance improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
wheerd committed Aug 3, 2017
1 parent 81df4b1 commit 2960af0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions matchpy/expressions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

def is_constant(expression):
"""Check if the given expression is constant, i.e. it does not contain Wildcards."""
if isinstance(expression, Expression):
return expression.is_constant
if isinstance(expression, Operation):
return all(is_constant(o) for o in op_iter(expression))
return not isinstance(expression, Wildcard)
Expand All @@ -23,6 +25,8 @@ def is_syntactic(expression):
Check if the given expression is syntactic, i.e. it does not contain sequence wildcards or
associative/commutative operations.
"""
if isinstance(expression, Expression):
return expression.is_syntactic
if isinstance(expression, (AssociativeOperation, CommutativeOperation)):
return False
if isinstance(expression, Operation):
Expand Down
2 changes: 1 addition & 1 deletion matchpy/expressions/substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
VariableReplacement = Union[Tuple['expressions.Expression', ...], Multiset, 'expressions.Expression']


class Substitution(Dict[str, VariableReplacement]):
class Substitution(dict):
"""Special :class:`dict` for substitutions with nicer formatting.
The key is a variable's name and the value the replacement for it.
Expand Down

0 comments on commit 2960af0

Please sign in to comment.