Skip to content

Inconsistent ast.parse result for python<3.11 and PEP654 #96587

Closed
@sobolevn

Description

@sobolevn

PEP654 introduced exception groups and except* in python3.11
Link: https://peps.python.org/pep-0654/

Right now it is possible to parse except* with older ast.parse(..., feature_version=(3, 10)).
Example:

>>> import ast
>>> code = '''
... try:
...   ...
... except* Exception:
...   ...
... '''
>>> 
>>> ast.parse(code)
<ast.Module object at 0x10c685410>
>>> ast.parse(code, feature_version=(3, 8))
<ast.Module object at 0x10c685280>
>>> 

Which is not correct.

But, unlike #96427 it is very simple to fix. And I belive it should be fixed.

I've already applied a patch and will send it shortly after :)

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions