Skip to content

Commit 6d038df

Browse files
committed
chore: update typing to collections.abc
Signed-off-by: Henry Schreiner <[email protected]>
1 parent ec9919a commit 6d038df

13 files changed

+44
-36
lines changed

bin/inspect_all_known_projects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from __future__ import annotations
1616

1717
import ast
18+
from collections.abc import Iterator
1819
from pathlib import Path
19-
from typing import Iterator
2020

2121
import click
2222
import yaml

cibuildwheel/architecture.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import platform as platform_module
55
import re
66
import sys
7+
from collections.abc import Set
78
from enum import Enum
89

910
from .typing import Final, Literal, PlatformName, assert_never
@@ -132,7 +133,7 @@ def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> set[A
132133

133134
def allowed_architectures_check(
134135
platform: PlatformName,
135-
architectures: set[Architecture],
136+
architectures: Set[Architecture],
136137
) -> None:
137138
allowed_architectures = Architecture.all_archs(platform)
138139

cibuildwheel/bashlex_eval.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

33
import subprocess
4+
from collections.abc import Sequence
45
from dataclasses import dataclass
5-
from typing import Callable, Dict, List, Sequence
6+
from typing import Callable, Dict, List # noqa: TID251
67

78
import bashlex
89

cibuildwheel/environment.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import dataclasses
4-
from typing import Any, Mapping, Sequence
4+
from collections.abc import Mapping, Sequence
5+
from typing import Any
56

67
import bashlex
78
import bashlex.errors

cibuildwheel/functools_cached_property_38.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

3+
import typing
4+
from collections.abc import Callable
35
from threading import RLock
4-
from typing import Any, Callable, Generic, TypeVar, overload
6+
from typing import Any, Generic, TypeVar
57

68
__all__ = ["cached_property"]
79

@@ -24,11 +26,11 @@ def __set_name__(self, owner: type[Any], name: str) -> None:
2426
msg = f"Cannot assign the same cached_property to two different names ({self.attrname!r} and {name!r})."
2527
raise TypeError(msg)
2628

27-
@overload
29+
@typing.overload
2830
def __get__(self, instance: None, owner: type[Any] | None = ...) -> cached_property[_T]:
2931
...
3032

31-
@overload
33+
@typing.overload
3234
def __get__(self, instance: object, owner: type[Any] | None = ...) -> _T:
3335
...
3436

cibuildwheel/linux.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import subprocess
44
import sys
55
import textwrap
6-
from collections.abc import Set
6+
from collections.abc import Iterator, Set
77
from dataclasses import dataclass
88
from pathlib import Path, PurePath, PurePosixPath
9-
from typing import Iterator, Tuple
9+
from typing import Tuple
1010

1111
from .architecture import Architecture
1212
from .logger import log

cibuildwheel/macos.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import shutil
99
import subprocess
1010
import sys
11-
from collections.abc import Set
11+
import typing
12+
from collections.abc import Sequence, Set
1213
from dataclasses import dataclass
1314
from pathlib import Path
14-
from typing import Sequence, Tuple, cast
15+
from typing import Tuple
1516

1617
from filelock import FileLock
1718

@@ -55,7 +56,7 @@ def get_macos_version() -> tuple[int, int]:
5556
"""
5657
version_str, _, _ = platform.mac_ver()
5758
version = tuple(map(int, version_str.split(".")[:2]))
58-
return cast(Tuple[int, int], version)
59+
return typing.cast(Tuple[int, int], version)
5960

6061

6162
def get_macos_sdks() -> list[str]:

cibuildwheel/oci_container.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import shutil
99
import subprocess
1010
import sys
11+
import typing
1112
import uuid
13+
from collections.abc import Sequence
1214
from pathlib import Path, PurePath, PurePosixPath
1315
from types import TracebackType
14-
from typing import IO, Dict, Sequence, cast
16+
from typing import IO, Dict
1517

1618
from cibuildwheel.util import CIProvider, detect_ci_provider
1719

@@ -329,7 +331,7 @@ def get_environment(self) -> dict[str, str]:
329331
capture_output=True,
330332
)
331333
)
332-
return cast(Dict[str, str], env)
334+
return typing.cast(Dict[str, str], env)
333335

334336
def environment_executor(self, command: list[str], environment: dict[str, str]) -> str:
335337
# used as an EnvironmentExecutor to evaluate commands and capture output

cibuildwheel/options.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import sys
1111
import textwrap
1212
import traceback
13+
import typing
14+
from collections.abc import Callable, Generator, Iterator, Mapping, Set
1315
from pathlib import Path
14-
from typing import Any, Callable, Dict, Generator, Iterator, List, Mapping, Union, cast
16+
from typing import Any, Dict, List, Union
1517

1618
if sys.version_info >= (3, 11):
1719
import tomllib
@@ -193,7 +195,7 @@ def __init__(
193195
*,
194196
platform: PlatformName,
195197
env: Mapping[str, str],
196-
disallow: dict[str, set[str]] | None = None,
198+
disallow: Mapping[str, Set[str]] | None = None,
197199
) -> None:
198200
self.platform = platform
199201
self.env = env
@@ -462,7 +464,7 @@ def globals(self) -> GlobalOptions:
462464
print(msg, file=sys.stderr)
463465
sys.exit(2)
464466

465-
container_engine = cast(ContainerEngine, container_engine_str)
467+
container_engine = typing.cast(ContainerEngine, container_engine_str)
466468

467469
return GlobalOptions(
468470
package_dir=package_dir,

cibuildwheel/util.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,15 @@
1111
import sys
1212
import textwrap
1313
import time
14+
import typing
1415
import urllib.request
16+
from collections.abc import Generator, Iterable, Sequence
1517
from dataclasses import dataclass
1618
from enum import Enum
1719
from functools import lru_cache
1820
from pathlib import Path, PurePath
1921
from time import sleep
20-
from typing import (
21-
Any,
22-
ClassVar,
23-
Generator,
24-
Iterable,
25-
Sequence,
26-
TextIO,
27-
TypeVar,
28-
cast,
29-
overload,
30-
)
22+
from typing import Any, ClassVar, TextIO, TypeVar
3123

3224
import bracex
3325
import certifi
@@ -107,7 +99,7 @@ def build_frontend_or_default(
10799
IS_WIN: Final[bool] = sys.platform.startswith("win")
108100

109101

110-
@overload
102+
@typing.overload
111103
def call(
112104
*args: PathOrStr,
113105
env: dict[str, str] | None = None,
@@ -117,7 +109,7 @@ def call(
117109
...
118110

119111

120-
@overload
112+
@typing.overload
121113
def call(
122114
*args: PathOrStr,
123115
env: dict[str, str] | None = None,
@@ -149,7 +141,7 @@ def call(
149141
result = subprocess.run(args_, check=True, shell=IS_WIN, env=env, cwd=cwd, **kwargs)
150142
if not capture_stdout:
151143
return None
152-
return cast(str, result.stdout)
144+
return typing.cast(str, result.stdout)
153145

154146

155147
def shell(*commands: str, env: dict[str, str] | None = None, cwd: PathOrStr | None = None) -> None:

cibuildwheel/windows.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
import subprocess
77
import sys
88
import textwrap
9-
from collections.abc import Set
9+
from collections.abc import Sequence, Set
1010
from contextlib import suppress
1111
from dataclasses import dataclass
1212
from functools import lru_cache
1313
from pathlib import Path
14-
from typing import Sequence
1514
from zipfile import ZipFile
1615

1716
from filelock import FileLock

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ select = [
136136
"RET", # flake8-return
137137
"RUF", # Ruff-specific
138138
"SIM", # flake8-simplify
139+
"TID251", # flake8-tidy-imports.banned-api
139140
"UP", # pyupgrade
140141
"YTT", # flake8-2020
141142
"EXE", # flake8-executable
@@ -151,6 +152,12 @@ target-version = "py37"
151152
typing-modules = ["cibuildwheel.typing"]
152153
flake8-unused-arguments.ignore-variadic-names = true
153154

155+
[tool.ruff.flake8-tidy-imports.banned-api]
156+
"typing.Mapping".msg = "Use collections.abc.Mapping instead."
157+
"typing.Callable".msg = "Use collections.abc.Callable instead."
158+
"typing.Iterator".msg = "Use collections.abc.Iterator instead."
159+
"typing.Sequence".msg = "Use collections.abc.Sequence instead."
160+
"typing.Set".msg = "Use collections.abc.Set instead."
154161

155162
[tool.ruff.per-file-ignores]
156163
"unit_test/*" = ["PLC1901"]

unit_test/option_prepare_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import platform as platform_module
44
import subprocess
55
import sys
6+
import typing
67
from contextlib import contextmanager
78
from pathlib import PurePosixPath
8-
from typing import cast
99
from unittest import mock
1010

1111
import pytest
@@ -52,7 +52,7 @@ def test_build_default_launches(monkeypatch):
5252

5353
main()
5454

55-
build_in_container = cast(mock.Mock, linux.build_in_container)
55+
build_in_container = typing.cast(mock.Mock, linux.build_in_container)
5656

5757
assert build_in_container.call_count == 4
5858

@@ -120,7 +120,7 @@ def test_build_with_override_launches(monkeypatch, tmp_path):
120120

121121
main()
122122

123-
build_in_container = cast(mock.Mock, linux.build_in_container)
123+
build_in_container = typing.cast(mock.Mock, linux.build_in_container)
124124

125125
assert build_in_container.call_count == 6
126126

0 commit comments

Comments
 (0)