Skip to content

Commit 883b424

Browse files
committed
Prune unnecessary typing imports
1 parent 89ad944 commit 883b424

File tree

34 files changed

+90
-150
lines changed

34 files changed

+90
-150
lines changed

vcorelib/args/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
# built-in
66
from argparse import ArgumentParser, Namespace
77
from typing import Callable as _Callable
8-
from typing import Dict as _Dict
98
from typing import Sequence as _Sequence
10-
from typing import Tuple as _Tuple
119

1210
CommandFunction = _Callable[[Namespace], int]
1311
CommandRegister = _Callable[[ArgumentParser], CommandFunction]
1412

15-
CommandLoader = _Callable[[], _Sequence[_Tuple[str, str, CommandRegister]]]
13+
CommandLoader = _Callable[[], _Sequence[tuple[str, str, CommandRegister]]]
1614

17-
CMDS: _Dict[str, CommandFunction] = {}
15+
CMDS: dict[str, CommandFunction] = {}
1816

1917

2018
def app_args(
21-
command_loader: CommandLoader, commands: _Dict[str, CommandFunction] = None
22-
) -> _Tuple[_Callable[[ArgumentParser], None], CommandFunction]:
19+
command_loader: CommandLoader, commands: dict[str, CommandFunction] = None
20+
) -> tuple[_Callable[[ArgumentParser], None], CommandFunction]:
2321
"""
2422
Create a function that can be used to add sub-command processing to an
2523
argument parser.

vcorelib/asyncio/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
from typing import Coroutine as _Coroutine
1818
from typing import Iterable as _Iterable
1919
from typing import Iterator
20-
from typing import List as _List
2120
from typing import Optional as _Optional
22-
from typing import Set as _Set
2321
from typing import TypeVar as _TypeVar
2422

2523
# internal
@@ -50,7 +48,7 @@ def log_task_exception(
5048

5149
def log_exceptions(
5250
tasks: _Iterable[_asyncio.Task[T]], logger: _LoggerType = None
53-
) -> _List[_asyncio.Task[T]]:
51+
) -> list[_asyncio.Task[T]]:
5452
"""Log task exception and return the list of tasks that aren't complete."""
5553

5654
for task in tasks:
@@ -147,7 +145,7 @@ def setter(sig: int, _: _Optional[_FrameType]) -> None:
147145
return setter
148146

149147

150-
def all_stop_signals() -> _Set[int]:
148+
def all_stop_signals() -> set[int]:
151149
"""Get a set of all stop signals on this platform."""
152150

153151
return {

vcorelib/asyncio/subprocess.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# built-in
66
from asyncio import create_subprocess_exec
77
from asyncio.subprocess import Process as _Process
8-
from typing import Tuple as _Tuple
98

109
# internal
1110
from vcorelib.logging import LoggerType
@@ -16,7 +15,7 @@
1615

1716
def log_process_info(
1817
program: str, *args: str, base: _Pathlike = None
19-
) -> _Tuple[str, str]:
18+
) -> tuple[str, str]:
2019
"""
2120
Get a relative-path program string and a space-delimeted string of the
2221
arguments, which have also been shortened against a possible relative path.
@@ -34,7 +33,7 @@ async def create_subprocess_exec_log(
3433
*args: str,
3534
stdout: int = None,
3635
stderr: int = None,
37-
rel: _Tuple[str, str] = None,
36+
rel: tuple[str, str] = None,
3837
**kwargs,
3938
) -> _Process:
4039
"""

vcorelib/dict/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
from enum import auto as _auto
99
from logging import getLogger
1010
from typing import Any as _Any
11-
from typing import Dict as _Dict
1211
from typing import Iterator as _Iterator
13-
from typing import List as _List
1412

1513
# internal
1614
from vcorelib.logging import LoggerType
1715

1816
_LOG = getLogger(__name__)
19-
GenericDict = _Dict[_Any, _Any]
20-
GenericStrDict = _Dict[str, _Any]
17+
GenericDict = dict[_Any, _Any]
18+
GenericStrDict = dict[str, _Any]
2119

2220

2321
def consume(data: GenericDict, key: _Any, default: _Any = None) -> _Any:
@@ -81,7 +79,7 @@ class MergeStrategy(_Enum):
8179
def merge_recursive(
8280
dict_a: GenericDict,
8381
dict_b: GenericDict,
84-
path: _List[str] = None,
82+
path: list[str] = None,
8583
expect_overwrite: bool = False,
8684
logger: LoggerType = None,
8785
strategy: MergeStrategy = MergeStrategy.RECURSIVE,
@@ -140,7 +138,7 @@ def merge_recursive(
140138
def merge(
141139
dict_a: GenericDict,
142140
dict_b: GenericDict,
143-
path: _List[str] = None,
141+
path: list[str] = None,
144142
expect_overwrite: bool = False,
145143
logger: LoggerType = None,
146144
strategy: MergeStrategy = MergeStrategy.RECURSIVE,
@@ -162,7 +160,7 @@ def merge(
162160

163161

164162
def merge_dicts(
165-
dicts: _List[GenericDict],
163+
dicts: list[GenericDict],
166164
expect_overwrite: bool = False,
167165
logger: LoggerType = None,
168166
strategy: MergeStrategy = MergeStrategy.RECURSIVE,

vcorelib/dict/codec.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import abc as _abc
88
from contextlib import contextmanager as _contextmanager
99
from typing import Any as _Any
10-
from typing import Dict as _Dict
1110
from typing import Iterator as _Iterator
1211
from typing import Optional as _Optional
1312
from typing import Type as _Type
1413
from typing import TypeVar as _TypeVar
15-
from typing import Union as _Union
1614

1715
# internal
1816
from vcorelib.io import ARBITER as _ARBITER
@@ -30,7 +28,7 @@ class JsonCodec(_abc.ABC, SchemaMixin):
3028
"""A simple JSON codec interface."""
3129

3230
@classmethod
33-
def normalize(cls: _Type[T], data: _Union[_JsonObject, T]) -> T:
31+
def normalize(cls: _Type[T], data: _JsonObject | T) -> T:
3432
"""Ensure that some object is an instance of this class."""
3533

3634
if not isinstance(data, cls):
@@ -112,7 +110,7 @@ def file_cache(
112110
cls: _Type[T],
113111
pathlike: _Pathlike,
114112
arbiter: _DataArbiter = _ARBITER,
115-
encode_kwargs: _Dict[str, _Any] = None,
113+
encode_kwargs: dict[str, _Any] = None,
116114
require_success: bool = False,
117115
**kwargs,
118116
) -> _Iterator[T]:

vcorelib/dict/env.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
# built-in
77
from os import environ as _environ
88
from typing import Any as _Any
9-
from typing import List as _List
109
from typing import Mapping as _Mapping
1110

1211
# internal
1312
from vcorelib.dict import GenericDict as _GenericDict
1413

15-
GenericList = _List[_Any]
14+
GenericList = list[_Any]
1615

1716

1817
def str_resolve_env_var(data: str, env: _Mapping[str, _Any] = None) -> str:
@@ -74,7 +73,7 @@ def dict_resolve_env_vars(
7473
in-place.
7574
"""
7675

77-
keys_to_remove: _List[str] = []
76+
keys_to_remove: list[str] = []
7877
to_update: _GenericDict = {}
7978

8079
for key, value in data.items():

vcorelib/graph/abc.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
# built-in
66
from collections import UserDict as _UserDict
7-
from typing import Dict as _Dict
87
from typing import Iterator as _Iterator
9-
from typing import Set as _Set
108
from typing import Type as _Type
119
from typing import TypeVar as _TypeVar
1210

@@ -90,11 +88,11 @@ def incoming(self, graph_kind: _Type[V] = None) -> _Iterator[T]:
9088
yield graph[label]
9189
break
9290

93-
def parallel(self) -> _Set[T]:
91+
def parallel(self) -> set[T]:
9492
"""Iterate over nodes that this instance shares parallel edges with."""
9593

96-
outgoing: _Set[T] = set(self.outgoing())
97-
incoming: _Set[T] = set(self.incoming())
94+
outgoing: set[T] = set(self.outgoing())
95+
incoming: set[T] = set(self.incoming())
9896
return outgoing.intersection(incoming)
9997

10098

@@ -107,7 +105,7 @@ class AbstractDiGraph(
107105
def __init__(
108106
self,
109107
name: str,
110-
initialdata: _Dict[str, T] = None,
108+
initialdata: dict[str, T] = None,
111109
graph_attrs: _AttributeMap = None,
112110
node_attrs: _AttributeMap = None,
113111
edge_attrs: _AttributeMap = None,
@@ -121,7 +119,7 @@ def __init__(
121119
self.edge_attrs = edge_attrs
122120

123121
# Source node -> a set of all destination edges.
124-
self.edges: _Dict[str, _Set[_GraphEdge]] = {}
122+
self.edges: dict[str, set[_GraphEdge]] = {}
125123

126124
def handle_node(self, label: str, node: T = None) -> T:
127125
"""

vcorelib/graph/edge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
"""
44

55
# built-in
6-
from typing import Dict as _Dict
76
from typing import NamedTuple
87
from typing import Optional as _Optional
98
from typing import TextIO as _TextIO
109

1110
# internal
1211
from vcorelib.graph.port import Port as _Port
1312

14-
AttributeMap = _Dict[str, str]
13+
AttributeMap = dict[str, str]
1514

1615

1716
def write_attributes(stream: _TextIO, data: AttributeMap = None) -> None:

vcorelib/graph/port.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
# built-in
99
from itertools import zip_longest as _zip_longest
10-
from typing import Dict as _Dict
1110
from typing import NamedTuple
1211
from typing import Optional as _Optional
13-
from typing import Set as _Set
1412
from typing import TextIO as _TextIO
1513

1614

@@ -79,22 +77,22 @@ class PortManager:
7977
def __init__(self) -> None:
8078
"""Initialize this port manager."""
8179

82-
self.outputs: _Dict[str, Port] = {}
83-
self.inputs: _Dict[str, Port] = {}
80+
self.outputs: dict[str, Port] = {}
81+
self.inputs: dict[str, Port] = {}
8482

85-
def inout_labels(self) -> _Set[str]:
83+
def inout_labels(self) -> set[str]:
8684
"""Get inout port labels."""
8785
return set(self.inputs.keys()).intersection(self.outputs.keys())
8886

89-
def input_labels(self, exclude_inout: bool = True) -> _Set[str]:
87+
def input_labels(self, exclude_inout: bool = True) -> set[str]:
9088
"""Get input port labels."""
9189

9290
result = set(self.inputs.keys())
9391
if exclude_inout:
9492
result -= self.inout_labels()
9593
return result
9694

97-
def output_labels(self, exclude_inout: bool = True) -> _Set[str]:
95+
def output_labels(self, exclude_inout: bool = True) -> set[str]:
9896
"""Get output port labels."""
9997

10098
result = set(self.outputs.keys())

vcorelib/io/arbiter/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from io import StringIO
77
import logging
88
from pathlib import Path
9-
from typing import List
109
from typing import Optional as _Optional
1110

1211
# third-party
@@ -143,7 +142,7 @@ async def decode_async(
143142
maxsplit: int = 1,
144143
expect_overwrite: bool = False,
145144
strategy: MergeStrategy = MergeStrategy.RECURSIVE,
146-
files_loaded: List[Path] = None,
145+
files_loaded: list[Path] = None,
147146
**kwargs,
148147
) -> LoadResult:
149148
"""Attempt to load data from a file using asyncio."""
@@ -229,7 +228,7 @@ def decode(
229228
maxsplit: int = 1,
230229
expect_overwrite: bool = False,
231230
strategy: MergeStrategy = MergeStrategy.RECURSIVE,
232-
files_loaded: List[Path] = None,
231+
files_loaded: list[Path] = None,
233232
**kwargs,
234233
) -> LoadResult:
235234
"""Attempt to load data from a file."""

vcorelib/io/archive/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import shutil
1111
import tarfile
1212
from typing import Optional as _Optional
13-
from typing import Tuple as _Tuple
1413
import zipfile
1514

1615
# internal
@@ -58,7 +57,7 @@ def extractall(
5857
maxsplit: int = 1,
5958
tar_filter: str = "tar",
6059
**extract_kwargs,
61-
) -> _Tuple[bool, int]:
60+
) -> tuple[bool, int]:
6261
"""
6362
Attempt to extract an arbitrary archive to a destination. Return whether or
6463
not this succeeded and how long it took.
@@ -96,7 +95,7 @@ def make_archive(
9695
ext_str: str = _DEFAULT_ARCHIVE_EXT,
9796
dst_dir: Path = None,
9897
**archive_kwargs,
99-
) -> _Tuple[_Optional[Path], int]:
98+
) -> tuple[_Optional[Path], int]:
10099
"""
101100
Create an archive from a source directory, named after that directory,
102101
and optionally moved to a destination other than the parent directory

vcorelib/io/file_writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from io import StringIO
99
import os
1010
from pathlib import Path
11-
from typing import Callable, Iterator, List, Optional, TextIO, Tuple
11+
from typing import Callable, Iterator, Optional, TextIO
1212

1313
# third-party
1414
import markdown
@@ -38,8 +38,8 @@ def wrap(self, data: str) -> str:
3838
return f"# {data}"
3939

4040

41-
LineWithComment = Tuple[str, Optional[str]]
42-
LinesWithComments = List[LineWithComment]
41+
LineWithComment = tuple[str, Optional[str]]
42+
LinesWithComments = list[LineWithComment]
4343

4444
MARKDOWN_EXTENSIONS = ["extra"]
4545

vcorelib/io/types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from typing import NamedTuple
1212
from typing import Optional as _Optional
1313
from typing import TextIO
14-
from typing import Tuple as _Tuple
1514
from typing import Union as _Union
1615

1716
# third-party
@@ -168,7 +167,7 @@ def __eq__(self, other: object) -> bool:
168167
assert isinstance(other, (LoadResult, tuple))
169168
return bool(self.data == other[0] and self.success == other[1])
170169

171-
def require_success(self, path: _Union[Path, str]) -> None:
170+
def require_success(self, path: Path | str) -> None:
172171
"""Raise a canonical exception if this result is a failure."""
173172
assert self.success, f"Couldn't load '{path}'!"
174173

@@ -192,7 +191,7 @@ def merge(
192191
)
193192

194193

195-
EncodeResult = _Tuple[bool, int]
194+
EncodeResult = tuple[bool, int]
196195
DataStream = _Union[TextIO, StringIO]
197196
StreamProcessor = _Callable[[DataStream], DataStream]
198197
DataDecoder = _Callable[[DataStream, LoggerType], LoadResult]

vcorelib/logging/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from logging.handlers import QueueHandler
1111
from queue import SimpleQueue
1212
from typing import Iterator as _Iterator
13-
from typing import Tuple
1413

1514
# internal
1615
from vcorelib.logging.args import (
@@ -60,7 +59,7 @@ def queue_handler(
6059
queue: LogRecordQueue = None,
6160
handler: QueueHandler = None,
6261
root_formatter: bool = True,
63-
) -> Tuple[LogRecordQueue, QueueHandler]:
62+
) -> tuple[LogRecordQueue, QueueHandler]:
6463
"""
6564
Set up and return a simple queue and logging queue handler. Use the
6665
provided objects if they already exist.

0 commit comments

Comments
 (0)