Skip to content

Commit bab6f06

Browse files
committed
chore: use from __future__ import annotations
1 parent 5b60cc8 commit bab6f06

Some content is hidden

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

71 files changed

+285
-166
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ repos:
1818
hooks:
1919
- id: pyupgrade
2020
args: ["--py37-plus"]
21+
exclude: ^cibuildwheel/resources/.*py$
2122

2223
# Autoremoves unused imports
2324
- repo: https://github.com/hadialqattan/pycln
@@ -31,6 +32,8 @@ repos:
3132
rev: 5.10.1
3233
hooks:
3334
- id: isort
35+
args: ["-a", "from __future__ import annotations"]
36+
exclude: ^cibuildwheel/resources/.*py$
3437

3538
- repo: https://github.com/psf/black
3639
rev: 22.6.0

bin/run_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import argparse
46
import os
57
import subprocess

bin/update_dependencies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import os
46
import shutil
57
import subprocess

bin/update_readme_changelog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import re
46
import sys
57
from pathlib import Path

cibuildwheel/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from __future__ import annotations
2+
13
__version__ = "2.8.0"

cibuildwheel/__main__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import os
35
import shutil
@@ -7,7 +9,6 @@
79
import textwrap
810
from pathlib import Path
911
from tempfile import mkdtemp
10-
from typing import List, Set, Union
1112

1213
import cibuildwheel
1314
import cibuildwheel.linux
@@ -257,7 +258,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
257258
log.warning(f"Can't delete temporary folder '{str(tmp_path)}'")
258259

259260

260-
def print_preamble(platform: str, options: Options, identifiers: List[str]) -> None:
261+
def print_preamble(platform: str, options: Options, identifiers: list[str]) -> None:
261262
print(
262263
textwrap.dedent(
263264
"""
@@ -287,13 +288,13 @@ def print_preamble(platform: str, options: Options, identifiers: List[str]) -> N
287288

288289

289290
def get_build_identifiers(
290-
platform: PlatformName, build_selector: BuildSelector, architectures: Set[Architecture]
291-
) -> List[str]:
292-
python_configurations: Union[
293-
List[cibuildwheel.linux.PythonConfiguration],
294-
List[cibuildwheel.windows.PythonConfiguration],
295-
List[cibuildwheel.macos.PythonConfiguration],
296-
]
291+
platform: PlatformName, build_selector: BuildSelector, architectures: set[Architecture]
292+
) -> list[str]:
293+
python_configurations: (
294+
list[cibuildwheel.linux.PythonConfiguration]
295+
| list[cibuildwheel.windows.PythonConfiguration]
296+
| list[cibuildwheel.macos.PythonConfiguration]
297+
)
297298

298299
if platform == "linux":
299300
python_configurations = cibuildwheel.linux.get_python_configurations(
@@ -313,7 +314,7 @@ def get_build_identifiers(
313314
return [config.identifier for config in python_configurations]
314315

315316

316-
def detect_warnings(*, options: Options, identifiers: List[str]) -> List[str]:
317+
def detect_warnings(*, options: Options, identifiers: list[str]) -> list[str]:
317318
warnings = []
318319

319320
# warn about deprecated {python} and {pip}

cibuildwheel/architecture.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from __future__ import annotations
2+
13
import functools
24
import platform as platform_module
35
import re
46
from enum import Enum
5-
from typing import Set
67

78
from .typing import Final, Literal, PlatformName, assert_never
89

@@ -32,11 +33,11 @@ class Architecture(Enum):
3233
ARM64 = "ARM64"
3334

3435
# Allow this to be sorted
35-
def __lt__(self, other: "Architecture") -> bool:
36+
def __lt__(self, other: Architecture) -> bool:
3637
return self.value < other.value
3738

3839
@staticmethod
39-
def parse_config(config: str, platform: PlatformName) -> "Set[Architecture]":
40+
def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
4041
result = set()
4142
for arch_str in re.split(r"[\s,]+", config):
4243
if arch_str == "auto":
@@ -54,7 +55,7 @@ def parse_config(config: str, platform: PlatformName) -> "Set[Architecture]":
5455
return result
5556

5657
@staticmethod
57-
def auto_archs(platform: PlatformName) -> "Set[Architecture]":
58+
def auto_archs(platform: PlatformName) -> set[Architecture]:
5859
native_architecture = Architecture(platform_module.machine())
5960
result = {native_architecture}
6061

@@ -72,7 +73,7 @@ def auto_archs(platform: PlatformName) -> "Set[Architecture]":
7273
return result
7374

7475
@staticmethod
75-
def all_archs(platform: PlatformName) -> "Set[Architecture]":
76+
def all_archs(platform: PlatformName) -> set[Architecture]:
7677
all_archs_map = {
7778
"linux": {
7879
Architecture.x86_64,
@@ -87,7 +88,7 @@ def all_archs(platform: PlatformName) -> "Set[Architecture]":
8788
return all_archs_map[platform]
8889

8990
@staticmethod
90-
def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> "Set[Architecture]":
91+
def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> set[Architecture]:
9192
archs_32 = {Architecture.i686, Architecture.x86}
9293
auto_archs = Architecture.auto_archs(platform)
9394

@@ -101,7 +102,7 @@ def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> "Set[
101102

102103
def allowed_architectures_check(
103104
platform: PlatformName,
104-
architectures: Set[Architecture],
105+
architectures: set[Architecture],
105106
) -> None:
106107

107108
allowed_architectures = Architecture.all_archs(platform)

cibuildwheel/bashlex_eval.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
from __future__ import annotations
2+
13
import subprocess
24
from dataclasses import dataclass
3-
from typing import Callable, Dict, List, Optional, Sequence
5+
from typing import Callable, Dict, List, Sequence
46

57
import bashlex
68

79
# a function that takes a command and the environment, and returns the result
810
EnvironmentExecutor = Callable[[List[str], Dict[str, str]], str]
911

1012

11-
def local_environment_executor(command: List[str], env: Dict[str, str]) -> str:
13+
def local_environment_executor(command: list[str], env: dict[str, str]) -> str:
1214
return subprocess.run(command, env=env, text=True, stdout=subprocess.PIPE, check=True).stdout
1315

1416

1517
@dataclass(frozen=True)
1618
class NodeExecutionContext:
17-
environment: Dict[str, str]
19+
environment: dict[str, str]
1820
input: str
1921
executor: EnvironmentExecutor
2022

2123

2224
def evaluate(
23-
value: str, environment: Dict[str, str], executor: Optional[EnvironmentExecutor] = None
25+
value: str, environment: dict[str, str], executor: EnvironmentExecutor | None = None
2426
) -> str:
2527
if not value:
2628
# empty string evaluates to empty string
@@ -101,7 +103,7 @@ def evaluate_nodes_as_compound_command(
101103

102104

103105
def evaluate_nodes_as_simple_command(
104-
nodes: List[bashlex.ast.node], context: NodeExecutionContext
106+
nodes: list[bashlex.ast.node], context: NodeExecutionContext
105107
) -> str:
106108
command = [evaluate_node(part, context=context) for part in nodes]
107109
return context.executor(command, context.environment)

cibuildwheel/environment.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
import dataclasses
2-
from typing import Any, Dict, List, Mapping, Optional, Sequence
4+
from typing import Any, Mapping, Sequence
35

46
import bashlex
57

@@ -12,7 +14,7 @@ class EnvironmentParseError(Exception):
1214
pass
1315

1416

15-
def split_env_items(env_string: str) -> List[str]:
17+
def split_env_items(env_string: str) -> list[str]:
1618
"""Splits space-separated variable assignments into a list of individual assignments.
1719
1820
>>> split_env_items('VAR=abc')
@@ -47,8 +49,8 @@ class EnvironmentAssignment(Protocol):
4749
def evaluated_value(
4850
self,
4951
*,
50-
environment: Dict[str, str],
51-
executor: Optional[bashlex_eval.EnvironmentExecutor] = None,
52+
environment: dict[str, str],
53+
executor: bashlex_eval.EnvironmentExecutor | None = None,
5254
) -> str:
5355
"""Returns the value of this assignment, as evaluated in the environment"""
5456

@@ -84,8 +86,8 @@ def __init__(self, assignment: str):
8486

8587
def evaluated_value(
8688
self,
87-
environment: Dict[str, str],
88-
executor: Optional[bashlex_eval.EnvironmentExecutor] = None,
89+
environment: dict[str, str],
90+
executor: bashlex_eval.EnvironmentExecutor | None = None,
8991
) -> str:
9092
return bashlex_eval.evaluate(self.value, environment=environment, executor=executor)
9193

@@ -100,16 +102,16 @@ def __eq__(self, other: object) -> bool:
100102

101103
@dataclasses.dataclass
102104
class ParsedEnvironment:
103-
assignments: List[EnvironmentAssignment]
105+
assignments: list[EnvironmentAssignment]
104106

105107
def __init__(self, assignments: Sequence[EnvironmentAssignment]) -> None:
106108
self.assignments = list(assignments)
107109

108110
def as_dictionary(
109111
self,
110112
prev_environment: Mapping[str, str],
111-
executor: Optional[bashlex_eval.EnvironmentExecutor] = None,
112-
) -> Dict[str, str]:
113+
executor: bashlex_eval.EnvironmentExecutor | None = None,
114+
) -> dict[str, str]:
113115
environment = dict(**prev_environment)
114116

115117
for assignment in self.assignments:

cibuildwheel/extra.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
These are utilities for the `/bin` scripts, not for the `cibuildwheel` program.
33
"""
44

5+
from __future__ import annotations
6+
57
from io import StringIO
6-
from typing import Dict, List
78

89
from .typing import Protocol
910

@@ -15,7 +16,7 @@ def __str__(self) -> str:
1516
...
1617

1718

18-
def dump_python_configurations(inp: Dict[str, Dict[str, List[Dict[str, Printable]]]]) -> str:
19+
def dump_python_configurations(inp: dict[str, dict[str, list[dict[str, Printable]]]]) -> str:
1920
output = StringIO()
2021
for header, values in inp.items():
2122
output.write(f"[{header}]\n")

0 commit comments

Comments
 (0)