22
33from __future__ import annotations
44
5+ import functools
56import re
67import sys
78from collections .abc import Iterable , Mapping
8- from functools import lru_cache
99from pathlib import Path
10- from typing import Any , Dict , Final , NamedTuple , Tuple
10+ from typing import Any , Final , NamedTuple
1111from typing_extensions import TypeAlias
1212
1313import pathspec
@@ -26,11 +26,6 @@ def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type:
2626PYTHON_VERSION : Final = f"{ sys .version_info .major } .{ sys .version_info .minor } "
2727
2828
29- # A backport of functools.cache for Python <3.9
30- # This module is imported by mypy_test.py, which needs to run on 3.8 in CI
31- cache = lru_cache (None )
32-
33-
3429def strip_comments (text : str ) -> str :
3530 return text .split ("#" )[0 ].strip ()
3631
@@ -81,7 +76,7 @@ def print_time(t: float) -> None:
8176# ====================================================================
8277
8378
84- @cache
79+ @functools . cache
8580def venv_python (venv_dir : Path ) -> Path :
8681 if sys .platform == "win32" :
8782 return venv_dir / "Scripts" / "python.exe"
@@ -93,7 +88,7 @@ def venv_python(venv_dir: Path) -> Path:
9388# ====================================================================
9489
9590
96- @cache
91+ @functools . cache
9792def parse_requirements () -> Mapping [str , Requirement ]:
9893 """Return a dictionary of requirements from the requirements file."""
9994 with REQUIREMENTS_PATH .open (encoding = "UTF-8" ) as requirements_file :
@@ -111,8 +106,8 @@ def get_mypy_req() -> str:
111106# Parsing the stdlib/VERSIONS file
112107# ====================================================================
113108
114- VersionTuple : TypeAlias = Tuple [int , int ]
115- SupportedVersionsDict : TypeAlias = Dict [str , Tuple [VersionTuple , VersionTuple ]]
109+ VersionTuple : TypeAlias = tuple [int , int ]
110+ SupportedVersionsDict : TypeAlias = dict [str , tuple [VersionTuple , VersionTuple ]]
116111
117112VERSIONS_PATH = STDLIB_PATH / "VERSIONS"
118113VERSION_LINE_RE = re .compile (r"^([a-zA-Z_][a-zA-Z0-9_.]*): ([23]\.\d{1,2})-([23]\.\d{1,2})?$" )
@@ -206,10 +201,10 @@ def allowlists(distribution_name: str) -> list[str]:
206201# ====================================================================
207202
208203
209- @cache
204+ @functools . cache
210205def get_gitignore_spec () -> pathspec .PathSpec :
211206 with open (".gitignore" , encoding = "UTF-8" ) as f :
212- return pathspec .PathSpec .from_lines ("gitwildmatch" , f . readlines () )
207+ return pathspec .GitIgnoreSpec .from_lines (f )
213208
214209
215210def spec_matches_path (spec : pathspec .PathSpec , path : Path ) -> bool :
0 commit comments