diff options
author | da-woods <dw-git@d-woods.co.uk> | 2022-08-01 17:58:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-01 17:58:24 +0100 |
commit | 1482bb8d159a8da3d2d7a53886a64602603ec11a (patch) | |
tree | 3244d50013ecad96260cc6a8d30cbb84ec3233c3 | |
parent | f7861ad3046ebfd51f40ca951214ce5f610af2d3 (diff) | |
download | cython-1482bb8d159a8da3d2d7a53886a64602603ec11a.tar.gz |
Apply suggestions from code review
Co-authored-by: scoder <stefan_ml@behnel.de>
-rw-r--r-- | Cython/Compiler/MatchCaseNodes.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/Cython/Compiler/MatchCaseNodes.py b/Cython/Compiler/MatchCaseNodes.py index 99fa70ccd..869c361c9 100644 --- a/Cython/Compiler/MatchCaseNodes.py +++ b/Cython/Compiler/MatchCaseNodes.py @@ -56,7 +56,7 @@ class MatchCaseNode(Node): class PatternNode(Node): """ - DW decided that PatternNode shouldn't be an expression because + PatternNode is not an expression because it does several things (evalutating a boolean expression, assignment of targets), and they need to be done at different times. @@ -67,23 +67,22 @@ class PatternNode(Node): child_attrs = ["as_targets"] def __init__(self, pos, **kwds): - super(PatternNode, self).__init__(pos, **kwds) if "as_targets" not in kwds: - self.as_targets = [] + kwds["as_targets"] = [] + super(PatternNode, self).__init__(pos, **kwds) def is_irrefutable(self): return False def get_targets(self): targets = self.get_main_pattern_targets() - for t in self.as_targets: - self.add_target_to_targets(targets, t.name) + for target in self.as_targets: + self.add_target_to_targets(targets, target.name) return targets def update_targets_with_targets(self, targets, other_targets): - intersection = targets.intersection(other_targets) - for i in intersection: - error(self.pos, "multiple assignments to name '%s' in pattern" % i) + for name in targets.intersection(other_targets): + error(self.pos, "multiple assignments to name '%s' in pattern" % name) targets.update(other_targets) def add_target_to_targets(self, targets, target): @@ -98,7 +97,7 @@ class PatternNode(Node): def validate_irrefutable(self): for attr in self.child_attrs: child = getattr(self, attr) - if isinstance(child, PatternNode): + if child is not None and isinstance(child, PatternNode): child.validate_irrefutable() |