Used to spell the type of "self" in classes. Example:: from typing import Self class Foo: def return_self(self) -> Self: ... return self This is especially useful for: - classmethods that are used as alternative construc
(self, parameters)
| 651 | |
| 652 | @_SpecialForm |
| 653 | def Self(self, parameters): |
| 654 | """Used to spell the type of "self" in classes. |
| 655 | |
| 656 | Example:: |
| 657 | |
| 658 | from typing import Self |
| 659 | |
| 660 | class Foo: |
| 661 | def return_self(self) -> Self: |
| 662 | ... |
| 663 | return self |
| 664 | |
| 665 | This is especially useful for: |
| 666 | - classmethods that are used as alternative constructors |
| 667 | - annotating an `__enter__` method which returns self |
| 668 | """ |
| 669 | raise TypeError(f"{self} is not subscriptable") |
| 670 | |
| 671 | |
| 672 | @_SpecialForm |
no outgoing calls