Skip to content

Commit 465f8ef

Browse files
committed
Fix a bunch of ruff errors
1 parent 6dac34f commit 465f8ef

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

pip_check_reqs/common.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
"""Common functions."""
33

4+
from __future__ import annotations
5+
46
import ast
57
import fnmatch
68
import imp
@@ -12,14 +14,8 @@
1214
from pathlib import Path
1315
from typing import (
1416
Callable,
15-
Dict,
1617
Generator,
1718
Iterable,
18-
List,
19-
Optional,
20-
Set,
21-
Tuple,
22-
Union,
2319
)
2420

2521
from packaging.markers import Marker
@@ -39,7 +35,7 @@ class FoundModule:
3935

4036
modname: str
4137
filename: str
42-
locations: List[Tuple[str, int]] = field(default_factory=list)
38+
locations: list[tuple[str, int]] = field(default_factory=list)
4339

4440
def __post_init__(self) -> None:
4541
self.filename = os.path.realpath(self.filename)
@@ -49,8 +45,8 @@ class _ImportVisitor(ast.NodeVisitor):
4945
def __init__(self, ignore_modules_function: Callable[[str], bool]) -> None:
5046
super().__init__()
5147
self._ignore_modules_function = ignore_modules_function
52-
self._modules: Dict[str, FoundModule] = {}
53-
self._location: Optional[str] = None
48+
self._modules: dict[str, FoundModule] = {}
49+
self._location: str | None = None
5450

5551
def set_location(self, location: str) -> None:
5652
self._location = location
@@ -120,7 +116,7 @@ def _add_module(self, modname: str, lineno: int) -> None:
120116
assert isinstance(self._location, str)
121117
self._modules[modname].locations.append((self._location, lineno))
122118

123-
def finalise(self) -> Dict[str, FoundModule]:
119+
def finalise(self) -> dict[str, FoundModule]:
124120
return self._modules
125121

126122

@@ -140,7 +136,7 @@ def find_imported_modules(
140136
paths: Iterable[Path],
141137
ignore_files_function: Callable[[str], bool],
142138
ignore_modules_function: Callable[[str], bool],
143-
) -> Dict[str, FoundModule]:
139+
) -> dict[str, FoundModule]:
144140
vis = _ImportVisitor(ignore_modules_function=ignore_modules_function)
145141
for path in paths:
146142
for filename in pyfiles(path):
@@ -157,11 +153,11 @@ def find_imported_modules(
157153

158154
def find_required_modules(
159155
ignore_requirements_function: Callable[
160-
[Union[str, ParsedRequirement]], bool,
156+
[str | ParsedRequirement], bool,
161157
],
162158
skip_incompatible: bool,
163159
requirements_filename: Path,
164-
) -> Set[NormalizedName]:
160+
) -> set[NormalizedName]:
165161
explicit = set()
166162
for requirement in parse_requirements(
167163
str(requirements_filename), session=PipSession(),
@@ -212,13 +208,13 @@ def is_package_file(path: str) -> str:
212208
return ""
213209

214210

215-
def ignorer(ignore_cfg: List[str]) -> Callable[..., bool]:
211+
def ignorer(ignore_cfg: list[str]) -> Callable[..., bool]:
216212
if not ignore_cfg:
217213
return lambda candidate: False
218214

219215
def ignorer_function(
220-
candidate: Union[str, ParsedRequirement],
221-
ignore_cfg: List[str] = ignore_cfg,
216+
candidate: str | ParsedRequirement,
217+
ignore_cfg: list[str] = ignore_cfg,
222218
) -> bool:
223219
for ignore in ignore_cfg:
224220
if isinstance(candidate, str):

pip_check_reqs/find_extra_reqs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
def find_extra_reqs(
28+
*,
2829
requirements_filename: Path,
2930
paths: Iterable[Path],
3031
ignore_files_function: Callable[[str], bool],

pip_check_reqs/find_missing_reqs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""Find missing requirements."""
22

3+
from __future__ import annotations
4+
35
import argparse
46
import collections
57
import importlib.metadata
68
import logging
79
import os
810
import sys
911
from pathlib import Path
10-
from typing import Callable, Iterable, List, Optional, Tuple
12+
from typing import Callable, Iterable
1113
from unittest import mock
1214

1315
from packaging.utils import NormalizedName, canonicalize_name
@@ -27,7 +29,7 @@ def find_missing_reqs(
2729
paths: Iterable[Path],
2830
ignore_files_function: Callable[[str], bool],
2931
ignore_modules_function: Callable[[str], bool],
30-
) -> List[Tuple[NormalizedName, List[FoundModule]]]:
32+
) -> list[tuple[NormalizedName, list[FoundModule]]]:
3133
# 1. find files used by imports in the code (as best we can without
3234
# executing)
3335
used_modules = common.find_imported_modules(
@@ -70,7 +72,7 @@ def find_missing_reqs(
7072
)
7173
for package_file in package_files:
7274
path = os.path.realpath(
73-
os.path.join(package_location, package_file),
75+
str(Path(package_location) / package_file),
7476
)
7577
installed_files[path] = package_name
7678
package_path = common.is_package_file(path)
@@ -116,7 +118,7 @@ def find_missing_reqs(
116118
return [(name, used[name]) for name in used if name not in explicit]
117119

118120

119-
def main(arguments: Optional[List[str]] = None) -> None:
121+
def main(arguments: list[str] | None = None) -> None:
120122
usage = "usage: %prog [options] files or directories"
121123
parser = argparse.ArgumentParser(usage)
122124
parser.add_argument("paths", type=Path, nargs="*")
@@ -173,7 +175,7 @@ def main(arguments: Optional[List[str]] = None) -> None:
173175
parse_result = parser.parse_args(arguments)
174176

175177
if parse_result.version:
176-
print(version_info())
178+
sys.stdout.write(version_info() + "\n")
177179
sys.exit(0)
178180

179181
if not parse_result.paths:

tests/test_find_missing_reqs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for `find_missing_reqs.py`."""
22

3+
from __future__ import annotations
34

45
import logging
56
import os
@@ -123,6 +124,7 @@ def test_main_no_spec(capsys: pytest.CaptureFixture[str]) -> None:
123124
],
124125
)
125126
def test_logging_config(
127+
*,
126128
caplog: pytest.LogCaptureFixture,
127129
verbose_cfg: bool,
128130
debug_cfg: bool,

0 commit comments

Comments
 (0)