Skip to content

Commit 483d130

Browse files
gh-131421: Fix ASDL tests (#133408)
PR #131419 broke this, but we failed to run tests on the PR due to a bug in our script.
1 parent 3084070 commit 483d130

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Lib/test/test_asdl_parser.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ def test_product(self):
6262
alias = self.types['alias']
6363
self.assertEqual(
6464
str(alias),
65-
'Product([Field(identifier, name), Field(identifier, asname, opt=True)], '
65+
'Product([Field(identifier, name), Field(identifier, asname, quantifiers=[OPTIONAL])], '
6666
'[Field(int, lineno), Field(int, col_offset), '
67-
'Field(int, end_lineno, opt=True), Field(int, end_col_offset, opt=True)])')
67+
'Field(int, end_lineno, quantifiers=[OPTIONAL]), Field(int, end_col_offset, quantifiers=[OPTIONAL])])')
6868

6969
def test_attributes(self):
7070
stmt = self.types['stmt']
7171
self.assertEqual(len(stmt.attributes), 4)
7272
self.assertEqual(repr(stmt.attributes[0]), 'Field(int, lineno)')
7373
self.assertEqual(repr(stmt.attributes[1]), 'Field(int, col_offset)')
74-
self.assertEqual(repr(stmt.attributes[2]), 'Field(int, end_lineno, opt=True)')
75-
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, opt=True)')
74+
self.assertEqual(repr(stmt.attributes[2]), 'Field(int, end_lineno, quantifiers=[OPTIONAL])')
75+
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, quantifiers=[OPTIONAL])')
7676

7777
def test_constructor_fields(self):
7878
ehandler = self.types['excepthandler']

Parser/asdl.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,21 @@ def __str__(self):
9191
return "{}{} {}".format(self.type, extra, self.name)
9292

9393
def __repr__(self):
94-
extra = ""
95-
for mod in self.quantifiers:
96-
if mod is Quantifier.SEQUENCE:
97-
extra += ", SEQUENCE"
98-
elif mod is Quantifier.OPTIONAL:
99-
extra += ", OPTIONAL"
94+
if self.quantifiers:
95+
texts = []
96+
for mod in self.quantifiers:
97+
if mod is Quantifier.SEQUENCE:
98+
texts.append("SEQUENCE")
99+
elif mod is Quantifier.OPTIONAL:
100+
texts.append("OPTIONAL")
101+
extra = ", quantifiers=[{}]".format(", ".join(texts))
102+
else:
103+
extra = ""
100104

101105
if self.name is None:
102-
return 'Field({0.type}, quantifiers=[{1}])'.format(self, extra)
106+
return 'Field({0.type}{1})'.format(self, extra)
103107
else:
104-
return 'Field({0.type}, {0.name}, quantifiers=[{1}])'.format(self, extra)
108+
return 'Field({0.type}, {0.name}{1})'.format(self, extra)
105109

106110
class Sum(AST):
107111
def __init__(self, types, attributes=None):

0 commit comments

Comments
 (0)