Skip to content

Commit a5216ef

Browse files
committed
Refactor type hints to use built-in types instead of typing module aliases
Signed-off-by: Tsuyoshi Hombashi <[email protected]>
1 parent d915e52 commit a5216ef

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

pathvalidate/_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import abc
66
import os
77
import sys
8-
from typing import ClassVar, Optional, Sequence, Tuple
8+
from collections.abc import Sequence
9+
from typing import ClassVar, Optional
910

1011
from ._common import normalize_platform, unprintable_ascii_chars
1112
from ._const import DEFAULT_MIN_LEN, Platform
@@ -27,7 +28,7 @@ def platform(self) -> Platform:
2728
return self.__platform
2829

2930
@property
30-
def reserved_keywords(self) -> Tuple[str, ...]:
31+
def reserved_keywords(self) -> tuple[str, ...]:
3132
return self._additional_reserved_names
3233

3334
@property

pathvalidate/_common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import string
99
import sys
1010
from pathlib import PurePath
11-
from typing import Any, List, Optional
11+
from typing import Any, Optional
1212

1313
from ._const import Platform
1414
from ._types import PathType, PlatformType
@@ -71,15 +71,15 @@ def _is_not_null_string(value: Any) -> bool:
7171
return False
7272

7373

74-
def _get_unprintable_ascii_chars() -> List[str]:
74+
def _get_unprintable_ascii_chars() -> list[str]:
7575
return [chr(c) for c in range(128) if chr(c) not in string.printable]
7676

7777

7878
unprintable_ascii_chars = tuple(_get_unprintable_ascii_chars())
7979

8080

81-
def _get_ascii_symbols() -> List[str]:
82-
symbol_list: List[str] = []
81+
def _get_ascii_symbols() -> list[str]:
82+
symbol_list: list[str] = []
8383

8484
for i in range(128):
8585
c = chr(i)
@@ -151,7 +151,7 @@ def normalize_platform(name: Optional[PlatformType]) -> Platform:
151151
return Platform.UNIVERSAL
152152

153153

154-
def findall_to_str(match: List[Any]) -> str:
154+
def findall_to_str(match: list[Any]) -> str:
155155
return ", ".join([repr(text) for text in match])
156156

157157

pathvalidate/_filename.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import posixpath
77
import re
88
import warnings
9+
from collections.abc import Sequence
910
from pathlib import Path, PurePath
10-
from typing import Optional, Pattern, Sequence, Tuple
11+
from re import Pattern
12+
from typing import Optional
1113

1214
from ._base import AbstractSanitizer, AbstractValidator, BaseFile, BaseValidator
1315
from ._common import findall_to_str, is_nt_abspath, to_str, truncate_str, validate_pathtype
@@ -126,7 +128,7 @@ class FileNameValidator(BaseValidator):
126128
_MACOS_RESERVED_FILE_NAMES = (":",)
127129

128130
@property
129-
def reserved_keywords(self) -> Tuple[str, ...]:
131+
def reserved_keywords(self) -> tuple[str, ...]:
130132
common_keywords = super().reserved_keywords
131133

132134
if self._is_universal():

pathvalidate/_filepath.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import posixpath
88
import re
99
import warnings
10+
from collections.abc import Sequence
1011
from pathlib import Path, PurePath
11-
from typing import List, Optional, Pattern, Sequence, Tuple
12+
from re import Pattern
13+
from typing import Optional
1214

1315
from ._base import AbstractSanitizer, AbstractValidator, BaseFile, BaseValidator
1416
from ._common import findall_to_str, is_nt_abspath, to_str, validate_pathtype
@@ -93,7 +95,7 @@ def sanitize(self, value: PathType, replacement_text: str = "") -> PathType:
9395
unicode_filepath = os.path.normpath(unicode_filepath)
9496
sanitized_path = unicode_filepath
9597

96-
sanitized_entries: List[str] = []
98+
sanitized_entries: list[str] = []
9799
if drive:
98100
sanitized_entries.append(drive)
99101
for entry in sanitized_path.replace("\\", "/").split("/"):
@@ -147,7 +149,7 @@ class FilePathValidator(BaseValidator):
147149
_MACOS_RESERVED_FILE_PATHS = ("/", ":")
148150

149151
@property
150-
def reserved_keywords(self) -> Tuple[str, ...]:
152+
def reserved_keywords(self) -> tuple[str, ...]:
151153
common_keywords = super().reserved_keywords
152154

153155
if any([self._is_universal(), self._is_posix(), self._is_macos()]):

pathvalidate/_symbol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import re
6-
from typing import Sequence
6+
from collections.abc import Sequence
77

88
from ._common import ascii_symbols, to_str, unprintable_ascii_chars
99
from .error import InvalidCharError

pathvalidate/error.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import enum
6-
from typing import Dict, Optional
6+
from typing import Optional
77

88
from ._const import Platform
99

@@ -145,14 +145,14 @@ def __init__(self, *args, **kwargs) -> None: # type: ignore
145145
except IndexError:
146146
super().__init__(*args, **kwargs)
147147

148-
def as_slog(self) -> Dict[str, str]:
148+
def as_slog(self) -> dict[str, str]:
149149
"""Return a dictionary representation of the error.
150150
151151
Returns:
152152
Dict[str, str]: A dictionary representation of the error.
153153
"""
154154

155-
slog: Dict[str, str] = {
155+
slog: dict[str, str] = {
156156
"code": self.reason.code,
157157
ErrorAttrKey.DESCRIPTION: self.reason.description,
158158
}

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import os.path
6-
from typing import Dict, Type
76

87
import setuptools
98

@@ -13,10 +12,10 @@
1312
REQUIREMENT_DIR = "requirements"
1413
ENCODING = "utf8"
1514

16-
pkg_info: Dict[str, str] = {}
15+
pkg_info: dict[str, str] = {}
1716

1817

19-
def get_release_command_class() -> Dict[str, Type[setuptools.Command]]:
18+
def get_release_command_class() -> dict[str, type[setuptools.Command]]:
2019
try:
2120
from releasecmd import ReleaseCommand
2221
except ImportError:

0 commit comments

Comments
 (0)