Skip to content

Commit

Permalink
Refactor type hints to use built-in types instead of typing module al…
Browse files Browse the repository at this point in the history
…iases

Signed-off-by: Tsuyoshi Hombashi <[email protected]>
  • Loading branch information
thombashi committed Dec 29, 2024
1 parent d915e52 commit a5216ef
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
5 changes: 3 additions & 2 deletions pathvalidate/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import abc
import os
import sys
from typing import ClassVar, Optional, Sequence, Tuple
from collections.abc import Sequence
from typing import ClassVar, Optional

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

@property
def reserved_keywords(self) -> Tuple[str, ...]:
def reserved_keywords(self) -> tuple[str, ...]:
return self._additional_reserved_names

@property
Expand Down
10 changes: 5 additions & 5 deletions pathvalidate/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import string
import sys
from pathlib import PurePath
from typing import Any, List, Optional
from typing import Any, Optional

from ._const import Platform
from ._types import PathType, PlatformType
Expand Down Expand Up @@ -71,15 +71,15 @@ def _is_not_null_string(value: Any) -> bool:
return False


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


unprintable_ascii_chars = tuple(_get_unprintable_ascii_chars())


def _get_ascii_symbols() -> List[str]:
symbol_list: List[str] = []
def _get_ascii_symbols() -> list[str]:
symbol_list: list[str] = []

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


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


Expand Down
6 changes: 4 additions & 2 deletions pathvalidate/_filename.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import posixpath
import re
import warnings
from collections.abc import Sequence
from pathlib import Path, PurePath
from typing import Optional, Pattern, Sequence, Tuple
from re import Pattern
from typing import Optional

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

@property
def reserved_keywords(self) -> Tuple[str, ...]:
def reserved_keywords(self) -> tuple[str, ...]:
common_keywords = super().reserved_keywords

if self._is_universal():
Expand Down
8 changes: 5 additions & 3 deletions pathvalidate/_filepath.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import posixpath
import re
import warnings
from collections.abc import Sequence
from pathlib import Path, PurePath
from typing import List, Optional, Pattern, Sequence, Tuple
from re import Pattern
from typing import Optional

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

sanitized_entries: List[str] = []
sanitized_entries: list[str] = []
if drive:
sanitized_entries.append(drive)
for entry in sanitized_path.replace("\\", "/").split("/"):
Expand Down Expand Up @@ -147,7 +149,7 @@ class FilePathValidator(BaseValidator):
_MACOS_RESERVED_FILE_PATHS = ("/", ":")

@property
def reserved_keywords(self) -> Tuple[str, ...]:
def reserved_keywords(self) -> tuple[str, ...]:
common_keywords = super().reserved_keywords

if any([self._is_universal(), self._is_posix(), self._is_macos()]):
Expand Down
2 changes: 1 addition & 1 deletion pathvalidate/_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import re
from typing import Sequence
from collections.abc import Sequence

from ._common import ascii_symbols, to_str, unprintable_ascii_chars
from .error import InvalidCharError
Expand Down
6 changes: 3 additions & 3 deletions pathvalidate/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import enum
from typing import Dict, Optional
from typing import Optional

from ._const import Platform

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

def as_slog(self) -> Dict[str, str]:
def as_slog(self) -> dict[str, str]:
"""Return a dictionary representation of the error.
Returns:
Dict[str, str]: A dictionary representation of the error.
"""

slog: Dict[str, str] = {
slog: dict[str, str] = {
"code": self.reason.code,
ErrorAttrKey.DESCRIPTION: self.reason.description,
}
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import os.path
from typing import Dict, Type

import setuptools

Expand All @@ -13,10 +12,10 @@
REQUIREMENT_DIR = "requirements"
ENCODING = "utf8"

pkg_info: Dict[str, str] = {}
pkg_info: dict[str, str] = {}


def get_release_command_class() -> Dict[str, Type[setuptools.Command]]:
def get_release_command_class() -> dict[str, type[setuptools.Command]]:
try:
from releasecmd import ReleaseCommand
except ImportError:
Expand Down

0 comments on commit a5216ef

Please sign in to comment.