Skip to content
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

Implement support for PEP-695 #922

Closed
zsol opened this issue May 11, 2023 · 10 comments
Closed

Implement support for PEP-695 #922

zsol opened this issue May 11, 2023 · 10 comments
Labels
codemod Bundled codemods, visitors, metadata providers enhancement New feature or request parsing Converting source code into CST nodes

Comments

@zsol
Copy link
Member

zsol commented May 11, 2023

There will be:

These changes are scheduled to be included in 3.12

@zsol zsol added enhancement New feature or request parsing Converting source code into CST nodes codemod Bundled codemods, visitors, metadata providers labels May 11, 2023
@charliermarsh
Copy link

@zsol - Just for our own internal planning, would you expect / is it a goal for LibCST to support PEP 695 in time for the Python 3.12 release (2023-10-02, at time of writing)? Or will it follow after?

@zsol
Copy link
Member Author

zsol commented Aug 10, 2023

Yeah I want LibCST to support the latest available CPython release. We'll make it happen.

@gabriel4k2
Copy link

Really interested in contributing, even on small parts, on this. Is this mainly for maintainers (ie, internally) or are you guys open for contributions?

@zsol
Copy link
Member Author

zsol commented Aug 25, 2023

More than happy to accept contributions! Which parts are interesting? Grammar changes are pure Rust, CST are a mix of Python & Rust, scoping changes are pure Python

@zanieb
Copy link

zanieb commented Aug 25, 2023

If helpful, here are the changes in Ruff which includes references to the pyflakes implementation and RustPython parser changes :) astral-sh/ruff#6109

@zsol zsol linked a pull request Aug 28, 2023 that will close this issue
@zsol
Copy link
Member Author

zsol commented Aug 28, 2023

#1004 has the grammar and CST changes. Scoping changes seem way more complicated than I anticipated so it won't fit into this weekend :)

@JelleZijlstra
Copy link

https://jellezijlstra.github.io/pep695 has a lot of discussion of scoping, in case it's helpful.

@zsol zsol removed a link to a pull request Aug 28, 2023
@zsol
Copy link
Member Author

zsol commented Sep 16, 2023

I've got the scoping rules more-or-less implemented in #1014, but I have two questions:

  1. (this is about the PEP) How do type parameters on function and class definitions interact with decorators? Intuitively it feels like decorators should wrap the whole class so they should not have visibility into type variables declared on the thing they're decorating - but I haven't found anything specific about this in the PEP or the discussion you mentioned @JelleZijlstra
  2. (this is about my implementation) The way Scope provider changes for type annotations #1014 currently implements the scoping rules, a function's body will have access to the immediately enclosing class's declarations, but only if the function has type parameters. This is obviously incorrect, but I'm not sure how to address this.

@JelleZijlstra
Copy link

  1. Decorators are evaluated outside the annotation scope used for type params, meaning they don't have access to the type params. This is mentioned in the PEP if you search for "decorator". It's also discussed in the docs at https://docs.python.org/3.12/reference/compound_stmts.html#generic-classes

  2. Haven't looked at the code, but possibly looking at symtable.c in CPython can inspire a solution.

@charliermarsh
Copy link

This is awesome -- thank you @zsol! Are you able to publish a new version to crates.io with Python 3.12 support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codemod Bundled codemods, visitors, metadata providers enhancement New feature or request parsing Converting source code into CST nodes
Projects
None yet
Development

No branches or pull requests

5 participants