Python Glossary Русский

Python 3.5+until 3.13typingterm

typing.io / typing.re

removed

The typing.io (IO, TextIO, BinaryIO) and typing.re (Pattern, Match) pseudo-packages. Removed in Python 3.13 — import from typing or re.

Syntax

from typing.io import TextIO  # до 3.13

These were not real modules but namespaces inside typing: typing.io held IO, TextIO and BinaryIO, typing.re held Pattern and Match. They were removed because the same names always lived directly in typing, and two paths to one object only confused people. To migrate, change from typing.io import TextIO to from typing import TextIO (the same for IO and BinaryIO), and from typing.re import Pattern, Match to from re import Pattern, Match: since Python 3.9 re.Pattern and re.Match are subscriptable in annotations as re.Pattern[str], while typing.Pattern and typing.Match are deprecated.

Examples

# Python 3.13+
try:
    from typing.io import TextIO
except ModuleNotFoundError as e:
    print(type(e).__name__)  # → ModuleNotFoundError
# Python 3.13+
import re
from typing import TextIO
def first_word(stream: TextIO, rx: re.Pattern[str]) -> str:
    m = rx.search(stream.read())
    return m.group() if m else ''
import io
print(first_word(io.StringIO('hello world'), re.compile(r'\w+')))  # → hello
import typing
from typing.io import TextIO
from typing.re import Pattern
print(TextIO is typing.TextIO, Pattern is typing.Pattern)  # → True True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy