summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-07-17 10:48:52 +0100
committerGitHub <noreply@github.com>2022-07-17 10:48:52 +0100
commitda2732fccdfe38598f45c2a70fbeb6f1faa2df7e (patch)
tree4ff77754ed19cf8672d0004da361b55da141bad6
parentfe17d9533d13edf873674a946b9cdf788640428e (diff)
downloadcython-da2732fccdfe38598f45c2a70fbeb6f1faa2df7e.tar.gz
Apply suggestions from code review
Co-authored-by: scoder <stefan_ml@behnel.de>
-rw-r--r--Cython/Compiler/MatchCaseNodes.py5
-rw-r--r--Cython/Compiler/Parsing.py10
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(