ππ [3.15] better typing
October 27, 2026
ππ [3.15] better typing
day 11 of 15 days of Python 3.15
Hey there, π
How is your Python π going?
In this email weβll talk about the improvements made to typing in 3.15. π
See the future schedule here and links to the previous days: https://mathspp.com/python-315
Typing keeps getting better
Since static type hinting started in Python 3.5, every Python release brings with it improvements.
Hereβs a rundown of some of those.
Better TypedDict
TypedDict can now have extra items or it can be set to close to completely disallow extra items, regardless of their type.
This was covered yesterday and you can learn more here.
Improved TypeVarTuple
A type variable can be set to be bound to another type, or you can explicitly set its variance.
This is done when creating type variables manually:
from typing import TypeVar
T1 = TypeVar("T1")
T2 = TypeVar("T2", bound=str)
T3 = TypeVar("T3", covariant=True)
T4 = TypeVar("T4", contravariant=True)
T5 = TypeVar("T5", infer_variance=True)In Python 3.15, the interface of TypeVarTuple was expanded to also accept these keyword arguments.
The goal is to have TypeVar and TypeVarTuple with the same interface.
This means you can control the variance of a type variable tuple.
For the argument bound, the meaning of setting bound is yet to be defined.
Instance and subclass checks with protocols
Protocols can be used with isinstance and issubclass if you decorate them with @typing.runtime_checkable.
This property is not inherited.
Thus, in Python 3.15 itβs now deprecated to use isinstance and issubclass with protocols that inherit from runtime checkable protocols but that arenβt themselves marked as being runtime checkable.
This means fewer errors will slip through the cracks.
Meta-typing features
Python 3.15 also introduces TypeForm and @disjoint_base, two features that are more niche and typically directed at code that works with types at a higher level.
TypeForm can be used to annotate type form objects (like int, "bool", str | int, or list[bool]).
disjoint_base is used to decorate classes that canβt be inherited from simultaneously.
Further reading
You can learn more about each new feature by reading the full article here: https://mathspp.com/blog/typing-improvements-in-python-315
Tomorrow youβll learn about other nice things added to the standard library in Python 3.15.
See the future schedule here and links to the previous days: https://mathspp.com/python-315
You received this email (at [subscriber]) because you got my free Python book βPydonβtsβ or one of my other books/cheatsheets (or because you signed up directly!).
Rodrigo ππ
Β© 2026 mathspp insider ππ
228 Park Ave S, #29976, New York, New York 10003, United States