Cleanup: remove deprecated typing built-ins for extension logic
Deprecated since Python 3.9 but still used in many docs/examples.
This commit is contained in:
committed by
Philipp Oeser
parent
dfa1b14abf
commit
8fbc96c8e5
@@ -21,38 +21,34 @@ import zipfile
|
||||
|
||||
from typing import (
|
||||
Callable,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
Set,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
WheelSource = Tuple[
|
||||
WheelSource = tuple[
|
||||
# Key - doesn't matter what this is... it's just a handle.
|
||||
str,
|
||||
# A list of absolute wheel file-paths.
|
||||
List[str],
|
||||
list[str],
|
||||
]
|
||||
|
||||
|
||||
def _read_records_csv(filepath: str) -> List[List[str]]:
|
||||
def _read_records_csv(filepath: str) -> list[list[str]]:
|
||||
import csv
|
||||
with open(filepath, encoding="utf8", errors="surrogateescape") as fh:
|
||||
return list(csv.reader(fh.read().splitlines()))
|
||||
|
||||
|
||||
def _wheels_from_dir(dirpath: str) -> Tuple[
|
||||
def _wheels_from_dir(dirpath: str) -> tuple[
|
||||
# The key is:
|
||||
# wheel_id
|
||||
# The values are:
|
||||
# Top level directories.
|
||||
Dict[str, List[str]],
|
||||
dict[str, list[str]],
|
||||
# Unknown paths.
|
||||
List[str],
|
||||
list[str],
|
||||
]:
|
||||
result: Dict[str, List[str]] = {}
|
||||
paths_unused: Set[str] = set()
|
||||
result: dict[str, list[str]] = {}
|
||||
paths_unused: set[str] = set()
|
||||
|
||||
if not os.path.exists(dirpath):
|
||||
return result, list(paths_unused)
|
||||
@@ -73,7 +69,7 @@ def _wheels_from_dir(dirpath: str) -> Tuple[
|
||||
record_rows = _read_records_csv(filepath_record)
|
||||
|
||||
# Build top-level paths.
|
||||
toplevel_paths_set: Set[str] = set()
|
||||
toplevel_paths_set: set[str] = set()
|
||||
for row in record_rows:
|
||||
if not row:
|
||||
continue
|
||||
@@ -110,14 +106,14 @@ def _wheels_from_dir(dirpath: str) -> Tuple[
|
||||
return result, paths_unused_list
|
||||
|
||||
|
||||
def _wheel_info_dir_from_zip(filepath_wheel: str) -> Optional[Tuple[str, List[str]]]:
|
||||
def _wheel_info_dir_from_zip(filepath_wheel: str) -> Optional[tuple[str, list[str]]]:
|
||||
"""
|
||||
Return:
|
||||
- The "*-info" directory name which contains meta-data.
|
||||
- The top-level path list (excluding "..").
|
||||
"""
|
||||
dir_info = ""
|
||||
toplevel_paths: Set[str] = set()
|
||||
toplevel_paths: set[str] = set()
|
||||
|
||||
with zipfile.ZipFile(filepath_wheel, mode="r") as zip_fh:
|
||||
# This file will always exist.
|
||||
@@ -228,7 +224,7 @@ WHEEL_VERSION_RE = re.compile(r"(\d+)?(?:\.(\d+))?(?:\.(\d+))")
|
||||
|
||||
def wheel_version_from_filename_for_cmp(
|
||||
filename: str,
|
||||
) -> Tuple[int, int, int, str]:
|
||||
) -> tuple[int, int, int, str]:
|
||||
"""
|
||||
Extract the version number for comparison.
|
||||
Note that this only handled the first 3 numbers,
|
||||
@@ -256,13 +252,13 @@ def wheel_version_from_filename_for_cmp(
|
||||
|
||||
|
||||
def wheel_list_deduplicate_as_skip_set(
|
||||
wheel_list: List[WheelSource],
|
||||
) -> Set[str]:
|
||||
wheel_list: list[WheelSource],
|
||||
) -> set[str]:
|
||||
"""
|
||||
Return all wheel paths to skip.
|
||||
"""
|
||||
wheels_to_skip: Set[str] = set()
|
||||
all_wheels: Set[str] = {
|
||||
wheels_to_skip: set[str] = set()
|
||||
all_wheels: set[str] = {
|
||||
filepath
|
||||
for _, wheels in wheel_list
|
||||
for filepath in wheels
|
||||
@@ -273,7 +269,7 @@ def wheel_list_deduplicate_as_skip_set(
|
||||
|
||||
# Keep a map from the base name to the "best" wheel,
|
||||
# the other wheels get added to `wheels_to_skip` to be ignored.
|
||||
all_wheels_by_base: Dict[str, str] = {}
|
||||
all_wheels_by_base: dict[str, str] = {}
|
||||
|
||||
for wheel in all_wheels:
|
||||
wheel_filename = os.path.basename(wheel)
|
||||
@@ -315,7 +311,7 @@ def apply_action(
|
||||
*,
|
||||
local_dir: str,
|
||||
local_dir_site_packages: str,
|
||||
wheel_list: List[WheelSource],
|
||||
wheel_list: list[WheelSource],
|
||||
remove_error_fn: Callable[[str, Exception], None],
|
||||
debug: bool,
|
||||
) -> None:
|
||||
@@ -337,10 +333,10 @@ def apply_action(
|
||||
wheels_installed, _paths_unknown = _wheels_from_dir(local_dir_site_packages)
|
||||
|
||||
# Wheels and their top level directories (which would be installed).
|
||||
wheels_packages: Dict[str, List[str]] = {}
|
||||
wheels_packages: dict[str, list[str]] = {}
|
||||
|
||||
# Map the wheel ID to path.
|
||||
wheels_dir_info_to_filepath_map: Dict[str, str] = {}
|
||||
wheels_dir_info_to_filepath_map: dict[str, str] = {}
|
||||
|
||||
# NOTE(@ideasman42): the wheels skip-set only de-duplicates at the level of the base-name of the wheels filename.
|
||||
# So the wheel file-paths:
|
||||
|
||||
Reference in New Issue
Block a user