-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent ast.parse
result for python<3.9
and PEP614
#96427
Comments
I fear that this is too much complexity unfortunately. Unless @isidentical or @lysnikolaou have string opinions about this, I prefer to mark is as won't fix. This whole idea of rejecting new constructs on compatibility mode is quite a lot of burden for a use case that's not clear (at least to me) and was not really discussed a lot. I don't think this is even fully documented... In any case, thanks for the issue and the work @sobolevn and sorry that we need to reject it :( |
No worries! I felt almost the same. Let's wait for others to comment. |
No strong opinion on my side. Plus I agree with @pablogsal. Should we maybe do a bit more research as to how |
I would be glad to. First, I will start with searching for real-life use-cases on github. |
MypyMy main use-case is It is possible via So, the initial problem was:
blackIt is also used by if sys.version_info >= (3, 8) and version >= (3,):
return ast.parse(src, filename, feature_version=version, type_comments=True) So, I think we can conlcude that this is a very specific feature for static analysis tools. Other projectsIt is also used by 100+ other projects (including some forks). https://cs.github.com/?q=feature_version%3D%20language%3APython&scopeName=All%20repos&scope=# |
PEP614 introduces relaxed decorator grammar in 3.9: https://peps.python.org/pep-0614/
Right now,
ast.parse
withfeature_version=(3, 8)
and bellow behave differently from specified python versions themself.For example,
main
branch is able to parse this code:While
python==3.8.x
is not able to:When looking at
we-love-parsers/pegen
- it does have a version check for this: https://github.com/we-like-parsers/pegen/blame/599255a5ba3930e86367cd3fc78fae91ee184dd5/data/python.gram#L660-L662Pros and Cons
I think that there are several key points to this, pros:
we-love-parsers/pegen
However, there are some serious cons to it:
I think it is up to @pablogsal and other core devs to decide.
Proposed solution
I've modified an existing
we-love-parsers/pegen
's solution a bit, here's what it looks like:I will send a PR with all the changes / tests / auto-generated files, so we can take a closer look and decide whether we want this or not.
The text was updated successfully, but these errors were encountered: