← 返回首页
gh-103763: Implement PEP 695 by JelleZijlstra · Pull Request #103764 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-103763: Implement PEP 695#103764

Merged
JelleZijlstra merged 232 commits into
python:mainfrom
JelleZijlstra:tvobject
May 16, 2023
Merged

gh-103763: Implement PEP 695#103764
JelleZijlstra merged 232 commits into
python:mainfrom
JelleZijlstra:tvobject

Conversation

JelleZijlstra commented Apr 24, 2023
edited
Loading

Copy link
Copy Markdown
Member

I will update this message as the status of the PR changes.

This is a complete implementation. It incorporates the changes in python/peps#3122, which were approved by the SC.

I wrote a detailed account of the changes in this PR at https://jellezijlstra.github.io/pep695

Reviews are welcome on any aspect of the implementation.

msfterictraut and others added 30 commits April 8, 2023 18:04
…This commit includes: 1. Parser updates 2. AST updates 3. typing.py updates 4. Unit tests It does not include the following: 5. Symtable updates 6. Compiler updates 7. C implementations of TypeVar, TypeVarTuple, ParamSpec, Generic
This fixes compilation for me locally.
This isn't fully functional, but it should be enough to unblock work on the runtime. I'll update this PR as I implement more.
496 hidden items Load more…

Copy link
Copy Markdown
Member Author

I think the refleaks are unrelated, probably #104510.

Eclips4 commented May 15, 2023

Copy link
Copy Markdown
Member

I think the refleaks are unrelated, probably #104510.

Yeah, you're right.
Fails in test_gzip, test_httpservers, test_nntplib, test_tarfile, test_xmlrpc related to isolation of io module.

JelleZijlstra merged commit 24d8b88 into python:main May 16, 2023

Copy link
Copy Markdown
Member

🎉

carljm added a commit to carljm/cpython that referenced this pull request May 16, 2023
* main: pythonGH-104510: Fix refleaks in `_io` base types (python#104516) pythongh-104539: Fix indentation error in logging.config.rst (python#104545) pythongh-104050: Don't star-import 'types' in Argument Clinic (python#104543) pythongh-104050: Add basic typing to CConverter in clinic.py (python#104538) pythongh-64595: Fix write file logic in Argument Clinic (python#104507) pythongh-104523: Inline minimal PGO rules (python#104524) pythongh-103861: Fix Zip64 extensions not being properly applied in some cases (python#103863) pythongh-69152: add method get_proxy_response_headers to HTTPConnection class (python#104248) pythongh-103763: Implement PEP 695 (python#103764) pythongh-104461: Run tkinter test_configure_screen on X11 only (pythonGH-104462) pythongh-104469: Convert _testcapi/watchers.c to use Argument Clinic (python#104503) pythongh-104482: Fix error handling bugs in ast.c (python#104483) pythongh-104341: Adjust tstate_must_exit() to Respect Interpreter Finalization (pythongh-104437) pythonGH-102613: Fix recursion error from `pathlib.Path.glob()` (pythonGH-104373)

carljm commented May 16, 2023

Copy link
Copy Markdown
Member

Congrats! Really excellent work on a tight timeframe.

zen-xu commented May 23, 2023

Copy link
Copy Markdown

Awesome!

But will python support Multiple bounds like rust

from typing import Protocol class Dance(Protocol): def dance(self): ... class Sing(Protocol): def sing(self): ... def perform[P: Dance + Sing](person: P): person.dance() person.sing()

sunmy2019 commented May 23, 2023
edited
Loading

Copy link
Copy Markdown
Member

But will python support Multiple bounds like rust

from typing import Protocol class Dance(Protocol): def dance(self): ... class Sing(Protocol): def sing(self): ... def perform[P: Dance + Sing](person: P): person.dance() person.sing()

It will not, at least not soon. Changes like this often need a PEP. If you are interested in it, new ideas are welcomed at https://discuss.python.org/c/ideas/6.

As for this specific question, I think you are asking for a typing.Intersection[Dance, Sing]. Some relevant issues here: python/typing#18

https://discuss.python.org/t/type-intersection-and-negation-in-type-annotations/23879

junkmd commented May 27, 2023

Copy link
Copy Markdown
Contributor

Adding the feature like a Multiple bounds by using a Intersection symbol and/or an & operator has been discussed for over 6 years at python/typing#213.

I hope that the adoption of PEP695 will lead to more discussion on this as well and improve the representation of type hints.

jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 22, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 22, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 22, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 22, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 22, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 22, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 23, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 25, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().
jacobtylerwalls added a commit to pylint-dev/astroid that referenced this pull request Jun 27, 2023
A C-accelerator was introduced for the typing module in Python 3.12 (see python/cpython#103764). Because a pure python source is no longer available, now we stub out the missing classes and provide some __class_getitem__ methods to allow subscripting like Type[int]. This may mean when 3.12 is the minimum, we can remove older brain features like infer_typing_alias().

Copy link
Copy Markdown
Member

@python/organization-owners, please block @johnnyjeannatasha as a spammer — see the review on this PR and the comment at a390ec2#commitcomment-124994466

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-typing type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Footer

© 2026 GitHub, Inc.