Annotate a method that returns its class with typing.Self
Answer: Self is a special type to represent the current enclosed class. PEP 673 introduces a concise way to annotate methods that return an instance of their class, compared with the TypeVar-based approach specified in PEP 484.
Return annotations
A common use case is a method that returns self. Annotate that return type as Self. In a subclass, the same method is understood to return the subclass, not only the base class. Foo().return_self() is revealed as Foo. SubclassOfFoo().return_self() is revealed as SubclassOfFoo.
When to prefer Self
Use Self instead of writing a new TypeVar bound to the class for that pattern.
| Self | TypeVar | |---|---| | Self | Special type for the current enclosed class | | return self | Common method annotation | | subclass | The return type follows the subclass | | PEP 673 | More concise than the PEP 484 TypeVar approach |
See also
Claims
- id: C1 claim: PEP 673 introduces a simple way to annotate methods that return an instance of their class. source: S1 evidence: "annotate methods that return an instance of their class"
- id: C2 claim: It behaves like the TypeVar approach in PEP 484, but is more concise. source: S1 evidence: "This behaves the same as the TypeVar -based approach specified in PEP 484"
- id: C3 claim: typing.Self is a special type for the current enclosed class. source: S2 evidence: "Special type to represent the current enclosed class"
Sources
- [S1] PEP 673 – Self Type. Python PEPs. https://peps.python.org/pep-0673/ . License: Public-Domain. Accessed 2026-11-19.
- [S2] typing — Support for type hints. Python docs. https://docs.python.org/3/library/typing.html . License: PSF-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 673 – Self Type; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 673 – Self Type; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0.
Cite this
iinventedlight. 2026. "Annotate a method that returns its class with typing.Self." iinventedlight Library, iil:note:9bmwwztd, version of 2026-11-19. https://iinventedlight.com/library/notes/python-typing-self/. License: CC-BY-4.0.
@misc{iil_note_9bmwwztd,
author = {{iinventedlight}},
title = {{Annotate a method that returns its class with typing.Self}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/python-typing-self/},
note = {Permanent ID iil:note:9bmwwztd. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-typing-self.table.json (table; CC-BY-4.0)
- python-typing-self.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-typing-self.md.