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 Report

Patch coverage: 67.02% and project coverage change: -0.34% ⚠️

Comparison is base (2064e20) 90.93% compared to head (f2e3012) 90.59%.
Report is 2 commits behind head on main.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1004      +/-   ##
==========================================
- Coverage   90.93%   90.59%   -0.34%     
==========================================
  Files         254      254              
  Lines       25972    26342     +370     
==========================================
+ Hits        23617    23865     +248     
- Misses       2355     2477     +122     
Files Changed Coverage Δ
libcst/__init__.py 91.30% <ø> (ø)
libcst/_nodes/tests/test_funcdef.py 87.23% <ø> (ø)
libcst/matchers/_return_types.py 100.00% <ø> (ø)
libcst/tests/test_tool.py 100.00% <ø> (ø)
libcst/_nodes/statement.py 91.43% <49.60%> (-3.50%) ⬇️
libcst/_typed_visitor.py 95.97% <70.70%> (-1.04%) ⬇️
libcst/_nodes/tests/test_await.py 100.00% <100.00%> (ø)
libcst/matchers/__init__.py 100.00% <100.00%> (ø)

☔ 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.

None yet

3 participants