mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-10 18:36:31 +08:00
Enable Ruff flake8-use-pathlib (PTH) (#13795)
Port existing code to pathlib
This commit is contained in:
@@ -11,6 +11,7 @@ STUBS_PATH: Final = TS_BASE_PATH / "stubs"
|
||||
|
||||
PYPROJECT_PATH: Final = TS_BASE_PATH / "pyproject.toml"
|
||||
REQUIREMENTS_PATH: Final = TS_BASE_PATH / "requirements-tests.txt"
|
||||
GITIGNORE_PATH: Final = TS_BASE_PATH / ".gitignore"
|
||||
|
||||
TESTS_DIR: Final = "@tests"
|
||||
TEST_CASES_DIR: Final = "test_cases"
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -16,7 +15,7 @@ from typing_extensions import TypeAlias
|
||||
import pathspec
|
||||
from packaging.requirements import Requirement
|
||||
|
||||
from .paths import REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, allowlists_path, test_cases_path
|
||||
from .paths import GITIGNORE_PATH, REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, allowlists_path, test_cases_path
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from _typeshed import OpenTextMode
|
||||
@@ -215,7 +214,7 @@ else:
|
||||
def NamedTemporaryFile(mode: OpenTextMode) -> TemporaryFileWrapper[str]: # noqa: N802
|
||||
def close(self: TemporaryFileWrapper[str]) -> None:
|
||||
TemporaryFileWrapper.close(self) # pyright: ignore[reportUnknownMemberType]
|
||||
os.remove(self.name)
|
||||
Path(self.name).unlink()
|
||||
|
||||
temp = tempfile.NamedTemporaryFile(mode, delete=False) # noqa: SIM115, TID251
|
||||
temp.close = MethodType(close, temp) # type: ignore[method-assign]
|
||||
@@ -229,7 +228,7 @@ else:
|
||||
|
||||
@functools.cache
|
||||
def get_gitignore_spec() -> pathspec.PathSpec:
|
||||
with open(".gitignore", encoding="UTF-8") as f:
|
||||
with GITIGNORE_PATH.open(encoding="UTF-8") as f:
|
||||
return pathspec.GitIgnoreSpec.from_lines(f)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user