diff options
author | da-woods <dw-git@d-woods.co.uk> | 2022-07-17 10:48:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-17 10:48:52 +0100 |
commit | da2732fccdfe38598f45c2a70fbeb6f1faa2df7e (patch) | |
tree | 4ff77754ed19cf8672d0004da361b55da141bad6 | |
parent | fe17d9533d13edf873674a946b9cdf788640428e (diff) | |
download | cython-da2732fccdfe38598f45c2a70fbeb6f1faa2df7e.tar.gz |
Apply suggestions from code review
Co-authored-by: scoder <stefan_ml@behnel.de>
-rw-r--r-- | Cython/Compiler/MatchCaseNodes.py | 5 | ||||
-rw-r--r-- | Cython/Compiler/Parsing.py | 10 |
2 files changed, 6 insertions, 9 deletions
diff --git a/Cython/Compiler/MatchCaseNodes.py b/Cython/Compiler/MatchCaseNodes.py index 579cf7d94..b4d39e318 100644 --- a/Cython/Compiler/MatchCaseNodes.py +++ b/Cython/Compiler/MatchCaseNodes.py @@ -1,7 +1,6 @@ # Nodes for structural pattern matching. # -# In a separate file because they're unlikely to be useful -# for much else +# In a separate file because they're unlikely to be useful for much else. from .Nodes import Node, StatNode from .Errors import error @@ -69,7 +68,7 @@ class PatternNode(Node): def __init__(self, pos, **kwds): super(PatternNode, self).__init__(pos, **kwds) - if not hasattr(self, "as_targets"): + if "as_targets" not in kwds: self.as_targets = [] def is_irrefutable(self): diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 23fb08dba..35f16fb7b 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -4006,7 +4006,7 @@ def p_match_statement(s, ctx): return MatchCaseNodes.MatchNode(pos, subject = subject, cases = cases) def p_case_block(s, ctx): - if not (s.sy=="IDENT" and s.systring == "case"): + if not (s.sy == "IDENT" and s.systring == "case"): s.error("Expected 'case'") s.next() pos = s.position() @@ -4062,8 +4062,8 @@ def p_maybe_star_pattern(s): ) return pattern else: - p = p_pattern(s) - return p + pattern = p_pattern(s) + return pattern def p_pattern(s): # try "as_pattern" then "or_pattern" @@ -4317,9 +4317,7 @@ def p_mapping_pattern(s): break if s.sy=='}': break - if s.sy != '}': - s.error("Expected '}'") - s.next() + s.expect('}') if double_star_set_twice is not None: return Nodes.ErrorNode(double_star_set_twice, what = "Double star capture set twice") return MatchCaseNodes.MatchMappingPatternNode( |