summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-12-08 20:40:55 +0000
committerda-woods <dw-git@d-woods.co.uk>2022-12-08 20:47:45 +0000
commitf9825ddec9178095760c83fc80430a6c477790ac (patch)
tree4b1812ce180d832e0f35ac4f389f0033b067d330
parent880b383de482cc8f4feae5c799c8a7e271575e1c (diff)
downloadcython-f9825ddec9178095760c83fc80430a6c477790ac.tar.gz
Type bools to bool for pattern matching
-rw-r--r--Cython/Compiler/Parsing.pxd2
-rw-r--r--Cython/Compiler/Parsing.py12
2 files changed, 9 insertions, 5 deletions
diff --git a/Cython/Compiler/Parsing.pxd b/Cython/Compiler/Parsing.pxd
index 997cdf513..fc3e2749f 100644
--- a/Cython/Compiler/Parsing.pxd
+++ b/Cython/Compiler/Parsing.pxd
@@ -63,7 +63,7 @@ cdef make_slice_nodes(pos, subscripts)
cpdef make_slice_node(pos, start, stop = *, step = *)
cdef p_atom(PyrexScanner s)
cdef p_atom_string(PyrexScanner s)
-cdef p_atom_ident_constants(PyrexScanner s)
+cdef p_atom_ident_constants(PyrexScanner s, bint bools_are_pybool = *)
@cython.locals(value=unicode)
cdef p_int_literal(PyrexScanner s)
cdef p_name(PyrexScanner s, name)
diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py
index 94fc2eca1..3fc6c3f26 100644
--- a/Cython/Compiler/Parsing.py
+++ b/Cython/Compiler/Parsing.py
@@ -746,7 +746,7 @@ def p_atom_string(s):
s.error("invalid string kind '%s'" % kind)
-def p_atom_ident_constants(s):
+def p_atom_ident_constants(s, bools_are_pybool=False):
"""
Returns None if it isn't one special-cased named constants.
Only calls s.next() if it successfully matches a matches.
@@ -754,12 +754,16 @@ def p_atom_ident_constants(s):
pos = s.position()
name = s.systring
result = None
+ if bools_are_pybool:
+ extra_kwds = {'type': Builtin.bool_type}
+ else:
+ extra_kwds = {}
if name == "None":
result = ExprNodes.NoneNode(pos)
elif name == "True":
- result = ExprNodes.BoolNode(pos, value=True)
+ result = ExprNodes.BoolNode(pos, value=True, **extra_kwds)
elif name == "False":
- result = ExprNodes.BoolNode(pos, value=False)
+ result = ExprNodes.BoolNode(pos, value=False, **extra_kwds)
elif name == "NULL" and not s.in_python_file:
result = ExprNodes.NullNode(pos)
if result:
@@ -4286,7 +4290,7 @@ def p_literal_pattern(s):
elif sy == 'IDENT':
# Note that p_atom_ident_constants includes NULL.
# This is a deliberate Cython addition to the pattern matching specification
- result = p_atom_ident_constants(s)
+ result = p_atom_ident_constants(s, bools_are_pybool=True)
if result:
return MatchCaseNodes.MatchValuePatternNode(pos, value=result, is_is_check=True)