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

PEP 695 - Type Parameter Syntax #1004

Merged
merged 1 commit into from
Aug 28, 2023
Merged

PEP 695 - Type Parameter Syntax #1004

merged 1 commit into from
Aug 28, 2023

Conversation

zsol
Copy link
Member

@zsol zsol commented Aug 27, 2023

PEP 695 - Type Parameter Syntax

This PR adds support for parsing and representing Type Parameters and Type Aliases as specified by PEP 695. What's missing are the scope rules, to be implemented in a future PR.

Notable (user visible) changes:

  • new TypeAlias CST node, which is a SmallStatement
  • new CST nodes to represent TypeVarLikes: TypeVar, TypeVarTuple, ParamSpec
  • new helper CST nodes: TypeParameters to serve as a container for multiple TypeVarLikes, and TypeParam which is a single item in a TypeParameters (owning the separating comma)
  • extended FunctionDef and ClassDef with an optional type_parameters field, as well as whitespace_after_type_parameters to own the extra whitespace between type parameters and the following token
    • these new fields are added after all others to avoid breaking callers passing in fields as positional arguments
  • in FunctionDef and ClassDef, whitespace_after_name now owns the whitespace before the type parameters if they exist

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 27, 2023
@zsol zsol force-pushed the pr1004 branch 4 times, most recently from 4082a51 to f2e3012 Compare August 28, 2023 09:15
@zsol zsol linked an issue Aug 28, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2023

Codecov Report

Attention: Patch coverage is 97.97468% with 8 lines in your changes missing coverage. Please review.

Project coverage is 91.04%. Comparing base (2064e20) to head (87461db).
Report is 122 commits behind head on main.

Files with missing lines Patch % Lines
libcst/_nodes/statement.py 96.85% 4 Missing ⚠️
libcst/_nodes/tests/test_type_alias.py 89.47% 2 Missing ⚠️
libcst/_nodes/tests/test_classdef.py 83.33% 1 Missing ⚠️
libcst/_nodes/tests/test_funcdef.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1004      +/-   ##
==========================================
+ Coverage   90.93%   91.04%   +0.10%     
==========================================
  Files         254      255       +1     
  Lines       25972    26366     +394     
==========================================
+ Hits        23617    24004     +387     
- Misses       2355     2362       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This PR adds support for parsing and representing Type Parameters and Type Aliases as specified by PEP 695. What's missing are the scope rules, to be implemented in a future PR.

Notable (user visible) changes:

- new `TypeAlias` CST node, which is a `SmallStatement`
- new CST nodes to represent TypeVarLikes: `TypeVar`, `TypeVarTuple`, `ParamSpec`
- new helper CST nodes:  `TypeParameters` to serve as a container for multiple TypeVarLikes, and `TypeParam` which is a single item in a `TypeParameters` (owning the separating comma)
- extended `FunctionDef` and `ClassDef` with an optional `type_parameters` field, as well as `whitespace_after_type_parameters` to own the extra whitespace between type parameters and the following token
  - these new fields are added after all others to avoid breaking callers passing in fields as positional arguments
- in `FunctionDef` and `ClassDef`, `whitespace_after_name` now owns the whitespace before the type parameters if they exist
@zsol zsol merged commit 9286446 into main Aug 28, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants