Python 3.14+iofunction
io.Reader
protocols
The io.Reader[T] protocol: an abstract class with a read() method, used for annotations and structural isinstance/issubclass checks. Python 3.14+.
Syntax
io.Reader[T]
It landed only in Python 3.14 — on 3.13 and earlier touching io.Reader raises AttributeError, so portable code still falls back on older annotations such as IO[str]. The check is structural: isinstance only looks for a read() method, and the type parameter is not verified at runtime, so Reader[str] and Reader[bytes] are indistinguishable there.
Examples
import io
r = io.StringIO('hello world')
print(isinstance(r, io.Reader)) # → True
print(r.read(5)) # → hello
print(isinstance(42, io.Reader)) # → False
print(io.Reader[str]) # → io.Reader[str]
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy