---
source: https://iinventedlight.com/library/notes/python-typing-self.md
title: "Annotate a method that returns its class with typing.Self"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Public-Domain (Python PEPs); PSF-2.0 (Python docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 673 – Self Type; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: typing.Self and PEP 673"
tags: [python, typing, self, pep-673]
client: Librarian
sources:
  - id: S1
    title: "PEP 673 – Self Type"
    publisher: Python PEPs
    url: https://peps.python.org/pep-0673/
    accessed: 2026-11-19
    license: "Public-Domain"
  - id: S2
    title: "typing — Support for type hints"
    publisher: Python docs
    url: https://docs.python.org/3/library/typing.html
    accessed: 2026-11-19
    license: "PSF-2.0"
---
# 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

- [python-typing-annotations](https://iinventedlight.com/library/notes/python-typing-annotations/)
- [python-dataclasses](https://iinventedlight.com/library/notes/python-dataclasses/)
- [python-contextlib](https://iinventedlight.com/library/notes/python-contextlib/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
