Skip to content

Commit f551cb4

Browse files
authored
Drop support for --python-version 3.9 (#21243)
Resolves #20154 It's getting close to time. Typeshed will drop support in a few days. Co-authored-by Codex
1 parent 4f94903 commit f551cb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+141
-412
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Next Release
44

5+
### Drop Support for Targeting Python 3.9
6+
7+
Mypy no longer supports type checking code with `--python-version 3.9`.
8+
Use `--python-version 3.10` or newer.
9+
510
## Mypy 1.20
611

712
We’ve just uploaded mypy 1.20.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).

docs/source/builtin_types.rst

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ See :ref:`dynamic-typing` for more details.
4040
Generic types
4141
.............
4242

43-
In Python 3.9 and later, built-in collection type objects support
44-
indexing:
43+
Built-in collection type objects support indexing:
4544

4645
====================== ===============================
4746
Type Description
@@ -65,13 +64,11 @@ strings and ``dict[Any, Any]`` is a dictionary of dynamically typed
6564
Python protocols. For example, a ``str`` object or a ``list[str]`` object is
6665
valid when ``Iterable[str]`` or ``Sequence[str]`` is expected.
6766
You can import them from :py:mod:`collections.abc` instead of importing from
68-
:py:mod:`typing` in Python 3.9.
67+
:py:mod:`typing`.
6968

70-
See :ref:`generic-builtins` for more details, including how you can
71-
use these in annotations also in Python 3.7 and 3.8.
69+
See :ref:`generic-builtins` for more details.
7270

73-
These legacy types defined in :py:mod:`typing` are needed if you need to support
74-
Python 3.8 and earlier:
71+
These legacy types defined in :py:mod:`typing` are also supported:
7572

7673
====================== ===============================
7774
Type Description
@@ -80,17 +77,5 @@ Type Description
8077
``Tuple[int, int]`` tuple of two ``int`` objects (``Tuple[()]`` is the empty tuple)
8178
``Tuple[int, ...]`` tuple of an arbitrary number of ``int`` objects
8279
``Dict[str, int]`` dictionary from ``str`` keys to ``int`` values
83-
``Iterable[int]`` iterable object containing ints
84-
``Sequence[bool]`` sequence of booleans (read-only)
85-
``Mapping[str, int]`` mapping from ``str`` keys to ``int`` values (read-only)
8680
``Type[C]`` type object of ``C`` (``C`` is a class/type variable/union of types)
8781
====================== ===============================
88-
89-
``List`` is an alias for the built-in type ``list`` that supports
90-
indexing (and similarly for ``dict``/``Dict`` and
91-
``tuple``/``Tuple``).
92-
93-
Note that even though ``Iterable``, ``Sequence`` and ``Mapping`` look
94-
similar to abstract base classes defined in :py:mod:`collections.abc`
95-
(formerly ``collections``), they are not identical, since the latter
96-
don't support indexing prior to Python 3.9.

docs/source/cheat_sheet_py3.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ Useful built-in types
4343
x: str = "test"
4444
x: bytes = b"test"
4545
46-
# For collections on Python 3.9+, the type of the collection item is in brackets
46+
# For collections, the type of the collection item is in brackets
4747
x: list[int] = [1]
4848
x: set[int] = {6, 7}
4949
5050
# For mappings, we need the types of both keys and values
51-
x: dict[str, float] = {"field": 2.0} # Python 3.9+
51+
x: dict[str, float] = {"field": 2.0}
5252
5353
# For tuples of fixed size, we specify the types of all the elements
54-
x: tuple[int, str, float] = (3, "yes", 7.5) # Python 3.9+
54+
x: tuple[int, str, float] = (3, "yes", 7.5)
5555
5656
# For tuples of variable size, we use one type and ellipsis
57-
x: tuple[int, ...] = (1, 2, 3) # Python 3.9+
57+
x: tuple[int, ...] = (1, 2, 3)
5858
5959
# On Python 3.8 and earlier, the name of the collection type is
6060
# capitalized, and the type is imported from the 'typing' module
@@ -67,13 +67,12 @@ Useful built-in types
6767
6868
from typing import Union, Optional
6969
70-
# On Python 3.10+, use the | operator when something could be one of a few types
71-
x: list[int | str] = [3, 5, "test", "fun"] # Python 3.10+
72-
# On earlier versions, use Union
70+
# Use the | operator when something could be one of a few types
71+
x: list[int | str] = [3, 5, "test", "fun"]
72+
# Union is equivalent
7373
x: list[Union[int, str]] = [3, 5, "test", "fun"]
7474
75-
# Use X | None for a value that could be None on Python 3.10+
76-
# Use Optional[X] on 3.9 and earlier; Optional[X] is the same as 'X | None'
75+
# Use X | None for a value that could be None; Optional[X] is the same as X | None
7776
x: str | None = "something" if some_condition() else None
7877
if x is not None:
7978
# Mypy understands x won't be None here because of the if-statement

docs/source/common_issues.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ subtly different, and it's important to understand how they differ to avoid pitf
671671

672672
.. code-block:: python
673673
674-
from typing import TypeAlias # "from typing_extensions" in Python 3.9 and earlier
674+
from typing import TypeAlias
675675
676676
class A: ...
677677
Alias: TypeAlias = A

docs/source/config_file.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Platform configuration
432432

433433
Specifies the Python version used to parse and check the target
434434
program. The string should be in the format ``MAJOR.MINOR`` --
435-
for example ``3.9``. The default is the version of the Python
435+
for example ``3.10``. The default is the version of the Python
436436
interpreter used to run mypy.
437437

438438
This option may only be set in the global section (``[mypy]``).
@@ -1255,7 +1255,7 @@ of your repo (or append it to the end of an existing ``pyproject.toml`` file) an
12551255
# mypy global options:
12561256
12571257
[tool.mypy]
1258-
python_version = "3.9"
1258+
python_version = "3.10"
12591259
warn_return_any = true
12601260
warn_unused_configs = true
12611261
exclude = [

docs/source/generics.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,7 @@ class in more recent versions of Python:
14191419

14201420
.. code-block:: python
14211421
1422-
>>> # Only relevant for Python 3.8 and below
1423-
>>> # If using Python 3.9 or newer, prefer the 'list[int]' syntax
1422+
>>> # Prefer the 'list[int]' syntax
14241423
>>> from typing import List
14251424
>>> List[int]
14261425
typing.List[int]

docs/source/getting_started.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@ union type. For example, ``int`` is a subtype of ``int | str``:
197197
else:
198198
return user_id
199199
200-
.. note::
201-
202-
If using Python 3.9 or earlier, use ``typing.Union[int, str]`` instead of
203-
``int | str``, or use ``from __future__ import annotations`` at the top of
204-
the file (see :ref:`runtime_troubles`).
205-
206200
The :py:mod:`typing` module contains many other useful types.
207201

208202
For a quick overview, look through the :ref:`mypy cheatsheet <cheat-sheet-py3>`.

docs/source/kinds_of_types.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,8 @@ such as ``int | None``. This is called an *optional type*:
315315
return None # Error: None not compatible with int
316316
return len(s)
317317
318-
To support Python 3.9 and earlier, you can use the :py:data:`~typing.Optional`
319-
type modifier instead, such as ``Optional[int]`` (``Optional[X]`` is
320-
the preferred shorthand for ``Union[X, None]``):
318+
You can also use the :py:data:`~typing.Optional` type modifier, such as
319+
``Optional[int]`` (``Optional[X]`` is the shorthand for ``Union[X, None]``):
321320

322321
.. code-block:: python
323322
@@ -515,12 +514,11 @@ distinguish them from implicit type aliases:
515514
it can't be used in contexts which require a class object. For example, it's
516515
not valid as a base class and it can't be used to construct instances.
517516

518-
There is also use an older syntax for defining explicit type aliases, which was
519-
introduced in Python 3.10 (:pep:`613`):
517+
There is also use an older syntax for defining explicit type aliases (:pep:`613`):
520518

521519
.. code-block:: python
522520
523-
from typing import TypeAlias # "from typing_extensions" in Python 3.9 and earlier
521+
from typing import TypeAlias
524522
525523
AliasType: TypeAlias = list[dict[tuple[int, str], set[int]]] | tuple[str, list[str]]
526524

docs/source/protocols.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ you need to define to implement each protocol.
6666
.. note::
6767
``typing`` also contains deprecated aliases to protocols and ABCs defined in
6868
:py:mod:`collections.abc`, such as :py:class:`Iterable[T] <typing.Iterable>`.
69-
These are only necessary in Python 3.8 and earlier, since the protocols in
70-
``collections.abc`` didn't yet support subscripting (``[]``) in Python 3.8,
71-
but the aliases in ``typing`` have always supported
72-
subscripting. In Python 3.9 and later, the aliases in ``typing`` don't provide
73-
any extra functionality.
7469

7570
Simple user-defined protocols
7671
*****************************

docs/source/type_inference_and_annotations.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ In these cases you can give the type explicitly using a type annotation:
9494
l: list[int] = [] # Create empty list of int
9595
d: dict[str, int] = {} # Create empty dictionary (str -> int)
9696
97-
.. note::
98-
99-
Using type arguments (e.g. ``list[int]``) on builtin collections like
100-
:py:class:`list`, :py:class:`dict`, :py:class:`tuple`, and :py:class:`set`
101-
only works in Python 3.9 and later. For Python 3.8 and earlier, you must use
102-
:py:class:`~typing.List` (e.g. ``List[int]``), :py:class:`~typing.Dict`, and
103-
so on.
104-
10597
10698
Compatibility of container types
10799
********************************

0 commit comments

Comments
 (0)