Skip to content

Commit cb3517d

Browse files
committed
types: Prefer namespaced TypeAlias usage
why: Style avoids direct imports from typing; stay consistent with commit 47188b8. what: - switch runtime aliases to t.TypeAlias across registry, _internal types/run/subprocess, and tests - remove direct TypeAlias imports
1 parent 9f771ca commit cb3517d

5 files changed

Lines changed: 14 additions & 23 deletions

File tree

src/libvcs/_internal/run.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def console_to_str(s: bytes) -> str:
3737

3838
if t.TYPE_CHECKING:
3939
_LoggerAdapter = logging.LoggerAdapter[logging.Logger]
40-
from typing import TypeAlias
4140
else:
4241
_LoggerAdapter = logging.LoggerAdapter
4342

@@ -96,12 +95,12 @@ def __call__(self, output: str, timestamp: datetime.datetime) -> None:
9695

9796

9897
if sys.platform == "win32":
99-
_ENV: TypeAlias = Mapping[str, str]
98+
_ENV: t.TypeAlias = Mapping[str, str]
10099
else:
101-
_ENV: TypeAlias = Mapping[bytes, StrPath] | Mapping[str, StrPath]
100+
_ENV: t.TypeAlias = Mapping[bytes, StrPath] | Mapping[str, StrPath]
102101

103102
_CMD = StrPath | Sequence[StrPath]
104-
_FILE: TypeAlias = int | t.IO[t.Any] | None
103+
_FILE: t.TypeAlias = int | t.IO[t.Any] | None
105104

106105

107106
def run(

src/libvcs/_internal/subprocess.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151

5252
from .dataclasses import SkipDefaultFieldsReprMixin
5353

54-
if t.TYPE_CHECKING:
55-
from typing import TypeAlias
56-
5754

5855
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
5956

@@ -64,13 +61,13 @@ def __init__(self, output: str, *args: object) -> None:
6461

6562

6663
if sys.platform == "win32":
67-
_ENV: TypeAlias = Mapping[str, str]
64+
_ENV: t.TypeAlias = Mapping[str, str]
6865
else:
69-
_ENV: TypeAlias = Mapping[bytes, StrOrBytesPath] | Mapping[str, StrOrBytesPath]
70-
_FILE: TypeAlias = None | int | t.IO[t.Any]
71-
_TXT: TypeAlias = bytes | str
66+
_ENV: t.TypeAlias = Mapping[bytes, StrOrBytesPath] | Mapping[str, StrOrBytesPath]
67+
_FILE: t.TypeAlias = None | int | t.IO[t.Any]
68+
_TXT: t.TypeAlias = bytes | str
7269
#: Command
73-
_CMD: TypeAlias = StrOrBytesPath | Sequence[StrOrBytesPath]
70+
_CMD: t.TypeAlias = StrOrBytesPath | Sequence[StrOrBytesPath]
7471

7572

7673
@dataclasses.dataclass(repr=False)

src/libvcs/_internal/types.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
import typing as t
1313
from os import PathLike
1414

15-
if t.TYPE_CHECKING:
16-
from typing import TypeAlias
17-
18-
StrPath: TypeAlias = str | PathLike[str] # stable
15+
StrPath: t.TypeAlias = str | PathLike[str] # stable
1916
""":class:`os.PathLike` or :class:`str`"""
2017

21-
StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes]
18+
StrOrBytesPath: t.TypeAlias = str | bytes | PathLike[str] | PathLike[bytes]
2219
""":class:`os.PathLike`, :class:`str` or bytes-like object"""
2320

2421

src/libvcs/url/registry.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
from __future__ import annotations
44

55
import typing as t
6-
from typing import TypeAlias
76

87
from libvcs._internal.module_loading import import_string
98
from .base import URLProtocol
109

11-
ParserLazyMap: TypeAlias = dict[str, type[URLProtocol] | str]
12-
ParserMap: TypeAlias = dict[str, type[URLProtocol]]
10+
ParserLazyMap: t.TypeAlias = dict[str, type[URLProtocol] | str]
11+
ParserMap: t.TypeAlias = dict[str, type[URLProtocol]]
1312

1413
DEFAULT_PARSERS: ParserLazyMap = {
1514
"git": "libvcs.url.git.GitURL",

tests/url/test_registry.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313

1414
if t.TYPE_CHECKING:
1515
from collections.abc import Callable
16-
from typing import TypeAlias
1716

18-
ParserMatchLazy: TypeAlias = Callable[[str], registry.ParserMatch]
19-
DetectVCSFixtureExpectedMatch: TypeAlias = registry.ParserMatch | ParserMatchLazy
17+
ParserMatchLazy: t.TypeAlias = Callable[[str], registry.ParserMatch]
18+
DetectVCSFixtureExpectedMatch: t.TypeAlias = registry.ParserMatch | ParserMatchLazy
2019

2120

2221
class DetectVCSFixture(t.NamedTuple):

0 commit comments

Comments
 (0)