On Wed, Nov 17, 2021 at 8:31 AM Pradeep Kumar Srinivasan
> This PEP  introduces a simple and intuitive way to annotate methods and classmethods that return an instance of their class. Such methods and classmethods occur quite frequently, but the existing way to annotate them correctly is quite arcane and error-prone. The PEP introduces a special type `Self` to represent the type of the `self` parameter, similar to the `this` type in TypeScript and the `Self` type in Rust. We have implementations for mypy and pyright. The PEP does not affect CPython directly except for the addition of one special form (Self) to typing.py .
> Since we have reached consensus on the PEP in typing-sig , we wanted to get your comments and suggestions before submitting to the Steering Council.
> Pradeep Kumar Srinivasan
> James Hilton-Balfe
> : https://www.python.org/dev/peps/pep-0673/
> : Adding `Self` to typing_extensions.py: https://github.com/python/typing/pull/933
> : See the comments from typing-sig members on the Google doc: https://docs.google.com/document/d/1ujuSMXDmSIOJpiZyV7mvBEC8P-y55AgSzXcvhrZciuI/edit?usp=sharing
Hello, and thanks for the PEP!
Sorry I'm late, but I have two curious questions about the PEP.
I don't think they should hold back accepting the PEP, but I'm
interested in the answers.
The PEP uses `reveal_type`, a function that's appeared in a few PEPs
already, but was never described. Is it a standard function in typing
tools, something specific to mypy, or pseudocode?
It's a function that doesn't exist at runtime, but when a type checker sees a call, it emits the inferred type of the argument. It originated with mypy but I believe has been adopted by all type checkers.
The PEP says "we reject Self in metaclasses."
"Metaclass" can mean "subclass of `type`", or it can refer to how a
value is used -- for example, you can write `class
In the PEP's example, is MyMetaclass rejected because:
- it's used as a metaclass in a class statement, or
- it's a subclass of `type` (so it's rejected even if unused), or
- it becomes a class of a class?
Or is the exact interpretation best left to the type checker?
Python-Dev mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Message archived at https://email@example.com/message/DVOQK3U6MOYXPRXF5OVLVLJBPEJRUIM5/
Code of Conduct: http://python.org/psf/codeofconduct/