Hello everyone, We've drafted a PEP for a `Self` type. This provides a painless, readable way to annotate methods and classmethods that return `self` or `cls(...)` respectively. We found that this pattern comes up a lot in real-world code; for example, typeshed uses this around 40% as often as popular types such as Dict or Callable. Please share your feedback in the Google Doc: https://docs.google.com/document/d/1ujuSMXDmSIOJpiZyV7mvBEC8P-y55AgSzXcvhrZc... Best, S Pradeep Kumar James Hilton-Balfe Original thread: https://mail.python.org/archives/list/typing-sig@python.org/thread/SJAANGA2C...
Thanks Pradeep & James. This is a very well-written spec. I think your proposal is elegant and provides good value. If anyone would like to experiment with the proposed "Self" type, I just published a new version of pyright that includes provisional support for this draft PEP. (For now, the "Self" type must be imported from "typing_extensions" rather than "typing", and obviously there's no runtime support yet.) -- Eric Traut Contributor to Pyright & Pylance Microsoft
participants (2)
-
Eric Traut
-
S Pradeep Kumar