Skip to content

Commit 9eb2b11

Browse files
authored
Merge pull request #684 from prospector-dev/prospector-checks
Prospector checks
2 parents 4ff1662 + 5459446 commit 9eb2b11

File tree

14 files changed

+60
-53
lines changed

14 files changed

+60
-53
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
echo "Checking prospector can run; don't care about messages found, only that it runs successfully"
3434
poetry run prospector --quiet --zero-exit
3535
echo "Prospector ran successfully."
36+
- name: Run Prospector checks
37+
run: poetry run prospector --output=pylint
3638
- name: Check packaging
3739
run: |
3840
echo "Building packages"

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
rev: v3.17.0
1414
hooks:
1515
- id: pyupgrade
16-
args: [--py38-plus]
16+
args: [--py39-plus]
1717
- repo: https://github.com/psf/black
1818
rev: 24.8.0
1919
hooks:

.prospector.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ pylint:
2929
- too-many-instance-attributes
3030
- too-many-function-args
3131
- too-many-statements
32+
- too-many-positional-arguments
33+
- no-else-return
3234

3335
mccabe:
3436
run: false
3537

3638
pycodestyle:
3739
disable:
3840
- E126
41+
- E501 # line too long
3942

4043
pydocstyle:
4144
run: false

prospector/config/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import re
33
import sys
44
from pathlib import Path
5-
from typing import Dict, List, Union
5+
from typing import Optional, Union
66

77
try: # Python >= 3.11
88
import re._constants as sre_constants
99
except ImportError:
10-
import sre_constants
10+
import sre_constants # pylint: disable=deprecated-module
1111

1212
from prospector import tools
1313
from prospector.autodetect import autodetect_libraries
@@ -26,7 +26,7 @@ class ProspectorConfig:
2626
# Also the 'too many instance attributes' warning is ignored, as this
2727
# is a config object and its sole purpose is to hold many properties!
2828

29-
def __init__(self, workdir: Path = None):
29+
def __init__(self, workdir: Optional[Path] = None):
3030
self.config, self.arguments = self._configure_prospector()
3131
self.paths = self._get_work_path(self.config, self.arguments)
3232
self.explicit_file_mode = all(p.is_file for p in self.paths)
@@ -36,8 +36,8 @@ def __init__(self, workdir: Path = None):
3636
self.libraries = self._find_used_libraries(self.config, self.profile)
3737
self.tools_to_run = self._determine_tool_runners(self.config, self.profile)
3838
self.ignores = self._determine_ignores(self.config, self.profile, self.libraries)
39-
self.configured_by: Dict[str, str] = {}
40-
self.messages: List[Message] = []
39+
self.configured_by: dict[str, str] = {}
40+
self.messages: list[Message] = []
4141

4242
def make_exclusion_filter(self):
4343
# Only close over the attributes required by the filter, rather
@@ -79,7 +79,7 @@ def get_tools(self, found_files):
7979
runners.append(tool)
8080
return runners
8181

82-
def replace_deprecated_tool_names(self) -> List[str]:
82+
def replace_deprecated_tool_names(self) -> list[str]:
8383
# pep8 was renamed pycodestyle ; pep257 was renamed pydocstyle
8484
# for backwards compatibility, these have been deprecated but will remain until prospector v2
8585
deprecated_found = []
@@ -112,7 +112,7 @@ def _configure_prospector(self):
112112
config = mgr.retrieve(*cfg.build_default_sources())
113113
return config, mgr.arguments
114114

115-
def _get_work_path(self, config, arguments) -> List[Path]:
115+
def _get_work_path(self, config, arguments) -> list[Path]:
116116
# Figure out what paths we're prospecting
117117
if config["path"]:
118118
paths = [Path(self.config["path"])]

prospector/finder.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Iterable, Iterator
12
from pathlib import Path
2-
from typing import Callable, Iterable, Iterator, List
3+
from typing import Callable, Optional
34

45
from prospector.exceptions import PermissionMissing
56
from prospector.pathutils import is_python_module, is_python_package, is_virtualenv
@@ -17,7 +18,7 @@ class FileFinder:
1718
is basically to know which files to pass to which tools to be inspected.
1819
"""
1920

20-
def __init__(self, *provided_paths: Path, exclusion_filters: Iterable[Callable] = None):
21+
def __init__(self, *provided_paths: Path, exclusion_filters: Optional[Iterable[Callable]] = None):
2122
"""
2223
:param provided_paths:
2324
A list of Path objects to search for files and modules - can be either directories or files
@@ -44,7 +45,7 @@ def __init__(self, *provided_paths: Path, exclusion_filters: Iterable[Callable]
4445
if path.is_dir():
4546
self._provided_dirs.append(path)
4647

47-
def make_syspath(self) -> List[Path]:
48+
def make_syspath(self) -> list[Path]:
4849
paths = set()
4950
for path in self._provided_dirs:
5051
paths.add(path)
@@ -55,7 +56,7 @@ def make_syspath(self) -> List[Path]:
5556
def is_excluded(self, path: Path) -> bool:
5657
return any(filt(path) for filt in self._exclusion_filters)
5758

58-
def _filter(self, paths: Iterable[Path]) -> List[Path]:
59+
def _filter(self, paths: Iterable[Path]) -> list[Path]:
5960
return [path for path in paths if not self.is_excluded(path)]
6061

6162
def _walk(self, directory: Path) -> Iterator[Path]:
@@ -71,7 +72,7 @@ def _walk(self, directory: Path) -> Iterator[Path]:
7172
yield path
7273

7374
@property
74-
def files(self) -> List[Path]:
75+
def files(self) -> list[Path]:
7576
"""
7677
List every individual file found from the given configuration.
7778
@@ -89,7 +90,7 @@ def files(self) -> List[Path]:
8990
return self._filter(files)
9091

9192
@property
92-
def python_packages(self) -> List[Path]:
93+
def python_packages(self) -> list[Path]:
9394
"""
9495
Lists every directory found in the given configuration which is a python module (that is,
9596
contains an `__init__.py` file).
@@ -99,7 +100,7 @@ def python_packages(self) -> List[Path]:
99100
return self._filter(d for d in self.directories if is_python_package(d))
100101

101102
@property
102-
def python_modules(self) -> List[Path]:
103+
def python_modules(self) -> list[Path]:
103104
"""
104105
Lists every directory found in the given configuration which is a python module (that is,
105106
contains an `__init__.py` file).
@@ -109,7 +110,7 @@ def python_modules(self) -> List[Path]:
109110
return self._filter(f for f in self.files if is_python_module(f))
110111

111112
@property
112-
def directories(self) -> List[Path]:
113+
def directories(self) -> list[Path]:
113114
"""
114115
Lists every directory found from the given configuration, regardless of its contents.
115116

prospector/formatters/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
__all__ = ("Formatter",)
44

55
from pathlib import Path
6+
from typing import Optional
67

78
from prospector.message import Message
89

910

1011
class Formatter(ABC):
11-
def __init__(self, summary, messages, profile, paths_relative_to: Path = None):
12+
def __init__(self, summary, messages, profile, paths_relative_to: Optional[Path] = None):
1213
self.summary = summary
1314
self.messages = messages
1415
self.profile = profile

prospector/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def make_tool_error_message(
7878
message: str,
7979
line: int = 0,
8080
character: int = 0,
81-
module: str = None,
82-
function: str = None,
81+
module: Optional[str] = None,
82+
function: Optional[str] = None,
8383
) -> Message:
8484
location = Location(path=filepath, module=module, function=function, line=line, character=character)
8585
return Message(source=source, code=code, location=location, message=message)

prospector/profiles/profile.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import pkgutil
55
from pathlib import Path
6-
from typing import Any, Dict, List, Optional, Tuple, Union
6+
from typing import Any, Optional, Union
77

88
import yaml
99

@@ -14,7 +14,7 @@
1414

1515

1616
class ProspectorProfile:
17-
def __init__(self, name: str, profile_dict: Dict[str, Any], inherit_order: List[str]):
17+
def __init__(self, name: str, profile_dict: dict[str, Any], inherit_order: list[str]):
1818
self.name = name
1919
self.inherit_order = inherit_order
2020

@@ -43,7 +43,7 @@ def __init__(self, name: str, profile_dict: Dict[str, Any], inherit_order: List[
4343
tool_conf = profile_dict.get(tool, {})
4444

4545
# set the defaults for everything
46-
conf: Dict[str, Any] = {"disable": [], "enable": [], "run": None, "options": {}}
46+
conf: dict[str, Any] = {"disable": [], "enable": [], "run": None, "options": {}}
4747
# use the "old" tool name
4848
conf.update(tool_conf)
4949

@@ -96,9 +96,9 @@ def as_yaml(self):
9696
@staticmethod
9797
def load(
9898
name_or_path: Union[str, Path],
99-
profile_path: List[Path],
99+
profile_path: list[Path],
100100
allow_shorthand: bool = True,
101-
forced_inherits: Optional[List[str]] = None,
101+
forced_inherits: Optional[list[str]] = None,
102102
):
103103
# First simply load all of the profiles and those that it explicitly inherits from
104104
data, inherits = _load_and_merge(
@@ -333,10 +333,10 @@ def _append_profiles(name, profile_path, data, inherit_list, allow_shorthand=Fal
333333

334334
def _load_and_merge(
335335
name_or_path: Union[str, Path],
336-
profile_path: List[Path],
336+
profile_path: list[Path],
337337
allow_shorthand: bool = True,
338-
forced_inherits: List[str] = None,
339-
) -> Tuple[Dict[str, Any], List[str]]:
338+
forced_inherits: Optional[list[str]] = None,
339+
) -> tuple[dict[str, Any], list[str]]:
340340
# First simply load all of the profiles and those that it explicitly inherits from
341341
data, inherit_list, shorthands_found = _load_profile(
342342
str(name_or_path),
@@ -419,12 +419,12 @@ def _transform_legacy(profile_dict):
419419

420420

421421
def _load_profile(
422-
name_or_path,
423-
profile_path,
424-
shorthands_found=None,
425-
already_loaded=None,
426-
allow_shorthand=True,
427-
forced_inherits=None,
422+
name_or_path: Union[str, Path],
423+
profile_path: list[Path],
424+
shorthands_found: Optional[set[str]] = None,
425+
already_loaded: Optional[list[Union[str, Path]]] = None,
426+
allow_shorthand: bool = True,
427+
forced_inherits: Optional[list[str]] = None,
428428
):
429429
# recursively get the contents of the basic profile and those it inherits from
430430
base_contents = _load_content(name_or_path, profile_path)

prospector/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def main():
189189

190190
paths = config.paths
191191
if len(paths) > 1 and not all(os.path.isfile(path) for path in paths):
192-
sys.stderr.write("\nIn multi-path mode, all inputs must be files, " "not directories.\n\n")
192+
sys.stderr.write("\nIn multi-path mode, all inputs must be files, not directories.\n\n")
193193
get_parser().print_usage()
194194
sys.exit(2)
195195

prospector/tools/profile_validator/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
try: # Python >= 3.11
55
import re._constants as sre_constants
66
except ImportError:
7-
import sre_constants
7+
import sre_constants # pylint: disable=deprecated-module
88

99
import yaml
1010

@@ -170,7 +170,7 @@ def add_message(code, message, setting):
170170
if "pep257" in parsed:
171171
add_message(
172172
CONFIG_DEPRECATED_CODE,
173-
"pep257 tool has been renamed to 'pydocstyle'. " "The name pep257 will be removed in prospector 2.0+.",
173+
"pep257 tool has been renamed to 'pydocstyle'. The name pep257 will be removed in prospector 2.0+.",
174174
"pep257",
175175
)
176176

0 commit comments

Comments
 (0)