Fundamentals 8 min read

New Typing Features in Python 3.13: ReadOnly, @warnings.deprecated, TypeIs, is_protocol, get_protocol_members, Default Types, NoDefault and Performance Improvements

Python 3.13 introduces several typing enhancements—including a ReadOnly type for TypedDict, a @warnings.deprecated decorator, the TypeIs narrowing helper, is_protocol and get_protocol_members utilities, default type support for TypeVar/ParamSpec/TypeVarTuple, the NoDefault sentinel, and notable performance gains by removing legacy typing namespaces.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
New Typing Features in Python 3.13: ReadOnly, @warnings.deprecated, TypeIs, is_protocol, get_protocol_members, Default Types, NoDefault and Performance Improvements

The recently released Python 3.13 continues the language’s pursuit of efficiency and elegance, adding seven new typing features that aim to improve code reliability and developer productivity.

1. ReadOnly type

The new ReadOnly type is a special construct for marking items in a TypedDict as immutable. Example usage:

<code>from typing import TypedDict, ReadOnly

class Leader(TypedDict):
    name: ReadOnly[str]
    age: int

author: Leader = {'name': 'Yang Zhou', 'age': 30}
author['age'] = 31  # no problem to change
author['name'] = 'Yang'  # Type check error: "name" is read‑only
</code>

Only the name field is declared as ReadOnly[str] , so static type checkers will flag any reassignment.

Note: ReadOnly can be used only inside TypedDict .

2. @warnings.deprecated decorator

Python 3.13 adds a convenient @warnings.deprecated decorator that marks functions or classes as deprecated while still allowing their use for a few more releases. IDEs such as PyCharm will display a strike‑through warning when the deprecated object is referenced.

Example (image omitted): the decorator triggers a visual cue in the editor.

3. TypeIs

The TypeIs protocol assists type narrowing. A function declared as def foo(arg: TypeA) -> TypeIs[TypeB]: ... returns True when arg is an instance of TypeB , enabling static checkers to infer a more precise type.

4. is_protocol

The new is_protocol function quickly checks whether an object is a Protocol type.

<code>from typing import is_protocol, Protocol

class PersonProto(Protocol):
    name: str
    age: int

print(is_protocol(PersonProto))  # True
print(is_protocol(int))         # False
</code>

5. get_protocol_members

get_protocol_members() returns a frozenset containing all attribute names defined in a Protocol .

<code>from typing import Protocol, get_protocol_members

class PersonProto(Protocol):
    name: str
    age: int

print(get_protocol_members(PersonProto))  # frozenset({'age', 'name'})
</code>

6. Default types for TypeVar, ParamSpec and TypeVarTuple

Python 3.13 allows default type arguments for TypeVar , ParamSpec and TypeVarTuple . Example:

<code>from typing import TypeVar
T = TypeVar("T", default=int)  # If no type is specified, T defaults to int
print(T.has_default())  # True
S = TypeVar("S")
print(S.has_default())  # False
</code>

The has_default() method reports whether a TypeVar has a default.

7. NoDefault

The NoDefault sentinel indicates that a type variable has no default value.

<code>from typing import TypeVar, NoDefault
T = TypeVar("T")
print(T.__default__ is NoDefault)  # True
S = TypeVar("S", default=None)
print(S.__default__ is NoDefault)  # False
</code>

8. Performance improvements and removals

By dropping dependencies on re and contextlib , the import time of the typing module is reduced by roughly one‑third. Additionally, the deprecated namespaces typing.io and typing.re have been removed, and the keyword‑argument method for creating TypedDict types (deprecated since Python 3.11) is no longer available.

PythonReadOnlytype hintstypingdeprecatedis_protocolPython3.13TypeIs
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.