Skip to content

Commit

Permalink
Replace deprecated typing imports with collections.abc (#18336)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Dec 30, 2024
1 parent f2a77ea commit 7982761
Show file tree
Hide file tree
Showing 92 changed files with 173 additions and 113 deletions.
3 changes: 2 additions & 1 deletion misc/analyze_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
import os.path
from collections import Counter
from typing import Any, Dict, Final, Iterable
from collections.abc import Iterable
from typing import Any, Dict, Final
from typing_extensions import TypeAlias as _TypeAlias

ROOT: Final = ".mypy_cache/3.5"
Expand Down
3 changes: 2 additions & 1 deletion misc/upload-pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
import tarfile
import tempfile
import venv
from collections.abc import Iterator
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from typing import Any, Iterator
from typing import Any
from urllib.request import urlopen

BASE = "https://api.github.com/repos"
Expand Down
3 changes: 2 additions & 1 deletion mypy/applytype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Callable, Iterable, Sequence
from collections.abc import Iterable, Sequence
from typing import Callable

import mypy.subtypes
from mypy.erasetype import erase_typevars
Expand Down
3 changes: 2 additions & 1 deletion mypy/argmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Callable, Sequence
from collections.abc import Sequence
from typing import TYPE_CHECKING, Callable

from mypy import nodes
from mypy.maptype import map_instance_to_supertype
Expand Down
3 changes: 2 additions & 1 deletion mypy/binder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from collections import defaultdict
from collections.abc import Iterator
from contextlib import contextmanager
from typing import DefaultDict, Iterator, List, NamedTuple, Optional, Tuple, Union
from typing import DefaultDict, List, NamedTuple, Optional, Tuple, Union
from typing_extensions import TypeAlias as _TypeAlias

from mypy.erasetype import remove_instance_last_known_values
Expand Down
4 changes: 1 addition & 3 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys
import time
import types
from collections.abc import Iterator, Mapping, Sequence
from typing import (
TYPE_CHECKING,
AbstractSet,
Expand All @@ -33,11 +34,8 @@
ClassVar,
Dict,
Final,
Iterator,
Mapping,
NamedTuple,
NoReturn,
Sequence,
TextIO,
)
from typing_extensions import TypeAlias as _TypeAlias, TypedDict
Expand Down
5 changes: 1 addition & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

import itertools
from collections import defaultdict
from collections.abc import Iterable, Iterator, Mapping, Sequence
from contextlib import ExitStack, contextmanager
from typing import (
AbstractSet,
Callable,
Dict,
Final,
Generic,
Iterable,
Iterator,
Mapping,
NamedTuple,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
Expand Down
3 changes: 2 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import itertools
import time
from collections import defaultdict
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from typing import Callable, ClassVar, Final, Iterable, Iterator, List, Optional, Sequence, cast
from typing import Callable, ClassVar, Final, List, Optional, cast
from typing_extensions import TypeAlias as _TypeAlias, assert_never, overload

import mypy.checker
Expand Down
3 changes: 2 additions & 1 deletion mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Callable, Sequence, cast
from collections.abc import Sequence
from typing import TYPE_CHECKING, Callable, cast

from mypy import meet, message_registry, subtypes
from mypy.erasetype import erase_typevars
Expand Down
3 changes: 2 additions & 1 deletion mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from __future__ import annotations

import re
from typing import TYPE_CHECKING, Callable, Dict, Final, Match, Pattern, Tuple, Union, cast
from re import Match, Pattern
from typing import TYPE_CHECKING, Callable, Dict, Final, Tuple, Union, cast
from typing_extensions import TypeAlias as _TypeAlias

import mypy.errorcodes as codes
Expand Down
16 changes: 2 additions & 14 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,8 @@
else:
import tomli as tomllib

from typing import (
Any,
Callable,
Dict,
Final,
Iterable,
List,
Mapping,
MutableMapping,
Sequence,
TextIO,
Tuple,
Union,
)
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
from typing import Any, Callable, Dict, Final, List, TextIO, Tuple, Union
from typing_extensions import TypeAlias as _TypeAlias

from mypy import defaults
Expand Down
3 changes: 2 additions & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Final, Iterable, List, Sequence
from collections.abc import Iterable, Sequence
from typing import TYPE_CHECKING, Final, List

import mypy.subtypes
import mypy.typeops
Expand Down
3 changes: 2 additions & 1 deletion mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import sys
import time
import traceback
from typing import Any, Callable, Mapping, NoReturn
from collections.abc import Mapping
from typing import Any, Callable, NoReturn

from mypy.dmypy_os import alive, kill
from mypy.dmypy_util import DEFAULT_STATUS_FILE, receive, send
Expand Down
3 changes: 2 additions & 1 deletion mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import sys
import time
import traceback
from collections.abc import Sequence
from contextlib import redirect_stderr, redirect_stdout
from typing import AbstractSet, Any, Callable, Final, List, Sequence, Tuple
from typing import AbstractSet, Any, Callable, Final, List, Tuple
from typing_extensions import TypeAlias as _TypeAlias

import mypy.build
Expand Down
3 changes: 2 additions & 1 deletion mypy/dmypy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import io
import json
from collections.abc import Iterable, Iterator
from types import TracebackType
from typing import Any, Final, Iterable, Iterator, TextIO
from typing import Any, Final, TextIO

from mypy.ipc import IPCBase

Expand Down
3 changes: 2 additions & 1 deletion mypy/erasetype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Callable, Container, cast
from collections.abc import Container
from typing import Callable, cast

from mypy.nodes import ARG_STAR, ARG_STAR2
from mypy.types import (
Expand Down
3 changes: 2 additions & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import sys
import traceback
from collections import defaultdict
from typing import Callable, Final, Iterable, NoReturn, Optional, TextIO, Tuple, TypeVar
from collections.abc import Iterable
from typing import Callable, Final, NoReturn, Optional, TextIO, Tuple, TypeVar
from typing_extensions import Literal, TypeAlias as _TypeAlias

from mypy import errorcodes as codes
Expand Down
3 changes: 2 additions & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Final, Iterable, Mapping, Sequence, TypeVar, cast, overload
from collections.abc import Iterable, Mapping, Sequence
from typing import Final, TypeVar, cast, overload

from mypy.nodes import ARG_STAR, FakeInfo, Var
from mypy.state import state
Expand Down
3 changes: 2 additions & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import re
import sys
import warnings
from typing import Any, Callable, Final, List, Optional, Sequence, TypeVar, Union, cast
from collections.abc import Sequence
from typing import Any, Callable, Final, List, Optional, TypeVar, Union, cast
from typing_extensions import Literal, overload

from mypy import defaults, errorcodes as codes, message_registry
Expand Down
3 changes: 2 additions & 1 deletion mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import functools
import os
from typing import Final, Sequence
from collections.abc import Sequence
from typing import Final

from mypy.fscache import FileSystemCache
from mypy.modulefinder import PYTHON_EXTENSIONS, BuildSource, matches_exclude, mypy_path
Expand Down
3 changes: 2 additions & 1 deletion mypy/fswatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from __future__ import annotations

import os
from typing import AbstractSet, Iterable, NamedTuple
from collections.abc import Iterable
from typing import AbstractSet, NamedTuple

from mypy.fscache import FileSystemCache

Expand Down
2 changes: 1 addition & 1 deletion mypy/gclogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import gc
import time
from typing import Mapping
from collections.abc import Mapping


class GcLogger:
Expand Down
3 changes: 2 additions & 1 deletion mypy/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import AbstractSet, Iterable, Iterator, TypeVar
from collections.abc import Iterable, Iterator
from typing import AbstractSet, TypeVar

T = TypeVar("T")

Expand Down
2 changes: 1 addition & 1 deletion mypy/indirection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Iterable
from collections.abc import Iterable

import mypy.types as types
from mypy.types import TypeVisitor
Expand Down
3 changes: 2 additions & 1 deletion mypy/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import NamedTuple, Sequence
from collections.abc import Sequence
from typing import NamedTuple

from mypy.constraints import (
SUBTYPE_OF,
Expand Down
3 changes: 2 additions & 1 deletion mypy/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import Sequence, overload
from collections.abc import Sequence
from typing import overload

import mypy.typeops
from mypy.expandtype import expand_type
Expand Down
3 changes: 2 additions & 1 deletion mypy/literals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Final, Iterable, Optional, Tuple
from collections.abc import Iterable
from typing import Any, Final, Optional, Tuple
from typing_extensions import TypeAlias as _TypeAlias

from mypy.nodes import (
Expand Down
3 changes: 2 additions & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import sys
import time
from collections import defaultdict
from collections.abc import Sequence
from gettext import gettext
from io import TextIOWrapper
from typing import IO, Any, Final, NoReturn, Protocol, Sequence, TextIO
from typing import IO, Any, Final, NoReturn, Protocol, TextIO

from mypy import build, defaults, state, util
from mypy.config_parser import (
Expand Down
3 changes: 2 additions & 1 deletion mypy/memprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import gc
import sys
from collections import defaultdict
from typing import Dict, Iterable, cast
from collections.abc import Iterable
from typing import Dict, cast

from mypy.nodes import FakeInfo, Node
from mypy.types import Type
Expand Down
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import difflib
import itertools
import re
from collections.abc import Collection, Iterable, Iterator, Sequence
from contextlib import contextmanager
from textwrap import dedent
from typing import Any, Callable, Collection, Final, Iterable, Iterator, List, Sequence, cast
from typing import Any, Callable, Final, List, cast

import mypy.typeops
from mypy import errorcodes as codes, message_registry
Expand Down
3 changes: 2 additions & 1 deletion mypy/metastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import os
import time
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Iterable
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
# We avoid importing sqlite3 unless we are using it so we can mostly work
Expand Down
3 changes: 1 addition & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import os
from abc import abstractmethod
from collections import defaultdict
from collections.abc import Iterator, Sequence
from enum import Enum, unique
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Final,
Iterator,
List,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
Expand Down
4 changes: 3 additions & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import re
import sys
import sysconfig
from typing import Any, Callable, Final, Mapping, Pattern
from collections.abc import Mapping
from re import Pattern
from typing import Any, Callable, Final

from mypy import defaults
from mypy.errorcodes import ErrorCode, error_codes
Expand Down
3 changes: 2 additions & 1 deletion mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from __future__ import annotations

from collections import defaultdict
from collections.abc import Iterable, Mapping
from functools import reduce
from typing import Final, Iterable, List, Mapping, cast
from typing import Final, List, cast
from typing_extensions import Literal

import mypy.plugin # To avoid circular imports.
Expand Down
3 changes: 2 additions & 1 deletion mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Final, Iterator, Literal
from collections.abc import Iterator
from typing import TYPE_CHECKING, Final, Literal

from mypy import errorcodes, message_registry
from mypy.expandtype import expand_type, expand_type_by_instance
Expand Down
Loading

0 comments on commit 7982761

Please sign in to comment.