Merge pull request #17822 from github/tausbn/python-more-parser-fixes

Python: A few more parser fixes
This commit is contained in:
Taus
2024-10-30 13:47:10 +01:00
committed by GitHub
15 changed files with 51603 additions and 53873 deletions

View File

@@ -14,4 +14,6 @@ x, y = z, w = 3, 4
s, *t = u
[v, *w] = x
o,p, = q,r,

View File

@@ -55,3 +55,13 @@
t = tuple(x for y in z)
[( t, ) for v in w]
[# comment
a for b in c # comment
# comment
] # comment
[# comment
d for e in f if g # comment
# comment
] # comment

View File

@@ -1,4 +1,4 @@
Module: [1, 0] - [22, 0]
Module: [1, 0] - [27, 0]
body: [
Try: [1, 0] - [1, 4]
body: [
@@ -133,4 +133,24 @@ Module: [1, 0] - [22, 0]
variable: Variable('v', None)
ctx: Load
]
Try: [23, 0] - [23, 4]
body: [
Pass: [24, 4] - [24, 8]
]
orelse: []
handlers: [
ExceptGroupStmt: [25, 0] - [26, 8]
type:
Name: [25, 8] - [25, 11]
variable: Variable('foo', None)
ctx: Load
name:
Name: [25, 15] - [25, 16]
variable: Variable('e', None)
ctx: Store
body: [
Pass: [26, 4] - [26, 8]
]
]
finalbody: []
]

View File

@@ -19,3 +19,8 @@ else:
finally:
u
v
try:
pass
except *foo as e:
pass

View File

@@ -0,0 +1,41 @@
Module: [1, 0] - [3, 0]
body: [
Assign: [1, 0] - [1, 42]
targets: [
Name: [1, 4] - [1, 26]
variable: Variable('tuple_typed_list_splat', None)
ctx: Store
]
value:
FunctionExpr: [1, 0] - [1, 42]
name: 'tuple_typed_list_splat'
args:
arguments
defaults: []
kw_defaults: []
annotations: []
varargannotation:
Starred: [1, 35] - [1, 40]
value:
Name: [1, 36] - [1, 40]
variable: Variable('ARGS', None)
ctx: Load
ctx: Load
kwargannotation: None
kw_annotations: []
returns: None
inner_scope:
Function: [1, 0] - [1, 42]
name: 'tuple_typed_list_splat'
type_parameters: []
args: []
vararg:
Name: [1, 28] - [1, 32]
variable: Variable('args', None)
ctx: Param
kwonlyargs: []
kwarg: None
body: [
Pass: [2, 4] - [2, 8]
]
]

View File

@@ -0,0 +1,2 @@
def tuple_typed_list_splat(*args : *ARGS):
pass

View File

@@ -49,6 +49,8 @@ class ParserTest(unittest.TestCase):
diff = e.output
if diff:
pytest.fail(diff.decode("utf-8"))
self.check_for_stdout_errors(logger)
self.assertEqual(self.capsys.readouterr().err, "")
os.remove(oldfile)
os.remove(newfile)
@@ -84,9 +86,15 @@ class ParserTest(unittest.TestCase):
diff = e.output
if diff:
pytest.fail(diff.decode("utf-8"))
self.check_for_stdout_errors(logger)
self.assertEqual(self.capsys.readouterr().err, "")
os.remove(actual)
def check_for_stdout_errors(self, logger):
if logger.had_errors():
logger.reset_error_count()
pytest.fail("Errors/warnings were logged to stdout during testing.")
def setup_tests():
test_folder = os.path.join(os.path.dirname(__file__), "parser")