Skip to content

Recent changes to CPython's grammar and PEG parser, PEP-617 #2759

Closed

Description

@sobolevn

Feature

CPython3.9+ support some new grammar rules, like () around with expression:

» python3.9 --version
Python 3.9.4
            
» python3.9
Python 3.9.4 (default, Apr  5 2021, 01:47:16) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> with (open('a') as f):
...     print(f)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'a'

But, RustPython does not support it:
Снимок экрана 2021-07-29 в 12 54 24

I think that the root of this problem is that new PEG parser is not supported: https://github.com/RustPython/RustPython/blob/master/parser/src/python.lalrpop

Python Documentation

https://www.python.org/dev/peps/pep-0617/

Activity

  1. DimitrisJim commented on Jul 29, 2021

    @DimitrisJim
    Member

    Yup, the project is currently targeting 3.8 so this shouldn't come as a surprise. Hopefully, at some point in the future, 3.9 will be the new goal and using a PEG parser will probably be needed.

  2. sobolevn commented on Jul 29, 2021

    @sobolevn
    ContributorAuthor

    Then, I guess we can change this line in the README, because 3.9>=3.8 🙂
    Снимок экрана 2021-07-29 в 19 09 31

  3. sobolevn commented on Jul 29, 2021

    @sobolevn
    ContributorAuthor

    Also: #2417

  4. youknowone commented on Aug 4, 2021

    @youknowone
    Member

    I think we are practically not pinning a target. Any patch for 3.9+ features will be appreciated.

  5. fanninpm commented on Aug 10, 2021

    @fanninpm
    Contributor

    I believe 3.8 is the absolute minimum because it's referenced in .github/workflows/ci.yaml.

  6. youknowone commented on Aug 10, 2021

    @youknowone
    Member

    we just can change it to 3.9 once we feel it is more convenient. that happened a few times.

  7. youknowone commented on Aug 11, 2021

    @youknowone
    Member
  8. sobolevn commented on Aug 11, 2021

    @sobolevn
    ContributorAuthor
  9. pinned this issue on Dec 10, 2022
  10. youknowone commented on Dec 10, 2022

    @youknowone
    Member

    We'd better to rewrite our parser based on same parser definition with CPython.

  11. youknowone commented on Dec 12, 2022

    @youknowone
    Member
  12. unpinned this issue on Feb 21, 2023
  13. youknowone commented on Oct 6, 2026

    @youknowone
    Member

    Parenthesized `with` (PEP 617) works on current main, e.g. `with (open("/dev/null") as f):` and multi-context parenthesized `with`. The parser is no longer the old LL parser. Closing.

    — commented by Grok 4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions