Skip to content

Commit

Permalink
Update typing_extensions imports for Python 3.9 (#18383)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Dec 30, 2024
1 parent 80e5e8b commit 1c427e7
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 31 deletions.
14 changes: 12 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@
import time
import types
from collections.abc import Iterator, Mapping, Sequence, Set as AbstractSet
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Final, NamedTuple, NoReturn, TextIO
from typing_extensions import TypeAlias as _TypeAlias, TypedDict
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Final,
NamedTuple,
NoReturn,
TextIO,
TypedDict,
)
from typing_extensions import TypeAlias as _TypeAlias

import mypy.semanal_main
from mypy.checker import TypeChecker
Expand Down
4 changes: 2 additions & 2 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from collections import defaultdict
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from typing import Callable, ClassVar, Final, Optional, cast
from typing_extensions import TypeAlias as _TypeAlias, assert_never, overload
from typing import Callable, ClassVar, Final, Optional, cast, overload
from typing_extensions import TypeAlias as _TypeAlias, assert_never

import mypy.checker
import mypy.errorcodes as codes
Expand Down
3 changes: 1 addition & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import sys
import warnings
from collections.abc import Sequence
from typing import Any, Callable, Final, Optional, TypeVar, Union, cast
from typing_extensions import Literal, overload
from typing import Any, Callable, Final, Literal, Optional, TypeVar, Union, cast, overload

from mypy import defaults, errorcodes as codes, message_registry
from mypy.errors import Errors
Expand Down
3 changes: 1 addition & 2 deletions mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from collections import defaultdict
from collections.abc import Iterable, Mapping
from functools import reduce
from typing import Final, cast
from typing_extensions import Literal
from typing import Final, Literal, cast

import mypy.plugin # To avoid circular imports.
from mypy.applytype import apply_generic_arguments
Expand Down
3 changes: 1 addition & 2 deletions mypy/semanal_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from __future__ import annotations

from abc import abstractmethod
from typing import Callable, Final, overload
from typing_extensions import Literal, Protocol
from typing import Callable, Final, Literal, Protocol, overload

from mypy_extensions import trait

Expand Down
16 changes: 7 additions & 9 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from contextlib import redirect_stderr, redirect_stdout
from functools import singledispatch
from pathlib import Path
from typing import Any, Generic, TypeVar, Union
from typing import Any, Final, Generic, TypeVar, Union
from typing_extensions import get_origin, is_typeddict

import mypy.build
Expand All @@ -52,7 +52,7 @@ def __repr__(self) -> str:
return "MISSING"


MISSING: typing_extensions.Final = Missing()
MISSING: Final = Missing()

T = TypeVar("T")
MaybeMissing: typing_extensions.TypeAlias = Union[T, Missing]
Expand All @@ -65,10 +65,10 @@ def __repr__(self) -> str:
return "<unrepresentable>"


UNREPRESENTABLE: typing_extensions.Final = Unrepresentable()
UNREPRESENTABLE: Final = Unrepresentable()


_formatter: typing_extensions.Final = FancyFormatter(sys.stdout, sys.stderr, False)
_formatter: Final = FancyFormatter(sys.stdout, sys.stderr, False)


def _style(message: str, **kwargs: Any) -> str:
Expand Down Expand Up @@ -1447,7 +1447,7 @@ def verify_typealias(
# ====================


IGNORED_MODULE_DUNDERS: typing_extensions.Final = frozenset(
IGNORED_MODULE_DUNDERS: Final = frozenset(
{
"__file__",
"__doc__",
Expand All @@ -1469,7 +1469,7 @@ def verify_typealias(
}
)

IGNORABLE_CLASS_DUNDERS: typing_extensions.Final = frozenset(
IGNORABLE_CLASS_DUNDERS: Final = frozenset(
{
# Special attributes
"__dict__",
Expand Down Expand Up @@ -1915,9 +1915,7 @@ class _Arguments:


# typeshed added a stub for __main__, but that causes stubtest to check itself
ANNOYING_STDLIB_MODULES: typing_extensions.Final = frozenset(
{"antigravity", "this", "__main__", "_ios_support"}
)
ANNOYING_STDLIB_MODULES: Final = frozenset({"antigravity", "this", "__main__", "_ios_support"})


def test_stubs(args: _Arguments, use_builtins_fixtures: bool = False) -> int:
Expand Down
3 changes: 1 addition & 2 deletions mypy/stubutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from collections import defaultdict
from collections.abc import Iterable, Iterator, Mapping
from contextlib import contextmanager
from typing import Final
from typing_extensions import overload
from typing import Final, overload

from mypy_extensions import mypyc_attr

Expand Down
3 changes: 1 addition & 2 deletions mypy/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import os
from collections.abc import Iterator
from contextlib import contextmanager
from typing import Callable, NamedTuple, TypeVar, cast
from typing_extensions import TypedDict
from typing import Callable, NamedTuple, TypedDict, TypeVar, cast

from mypy.argmap import map_actuals_to_formals
from mypy.build import Graph, State
Expand Down
3 changes: 1 addition & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import itertools
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from typing import Callable, Final, TypeVar
from typing_extensions import Protocol
from typing import Callable, Final, Protocol, TypeVar

from mypy import errorcodes as codes, message_registry, nodes
from mypy.errorcodes import ErrorCode
Expand Down
15 changes: 13 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
import sys
from abc import abstractmethod
from collections.abc import Iterable, Sequence
from typing import TYPE_CHECKING, Any, ClassVar, Final, NamedTuple, NewType, TypeVar, Union, cast
from typing_extensions import Self, TypeAlias as _TypeAlias, TypeGuard, overload
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
Final,
NamedTuple,
NewType,
TypeVar,
Union,
cast,
overload,
)
from typing_extensions import Self, TypeAlias as _TypeAlias, TypeGuard

import mypy.nodes
from mypy.bogus_type import Bogus
Expand Down
3 changes: 1 addition & 2 deletions mypy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import time
from collections.abc import Container, Iterable, Sequence, Sized
from importlib import resources as importlib_resources
from typing import IO, Any, Callable, Final, TypeVar
from typing_extensions import Literal
from typing import IO, Any, Callable, Final, Literal, TypeVar

orjson: Any
try:
Expand Down
3 changes: 1 addition & 2 deletions mypyc/irbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from collections.abc import Iterator, Sequence
from contextlib import contextmanager
from typing import Any, Callable, Final, Union
from typing_extensions import overload
from typing import Any, Callable, Final, Union, overload

from mypy.build import Graph
from mypy.maptype import map_instance_to_supertype
Expand Down

0 comments on commit 1c427e7

Please sign in to comment.