Skip to content

Commit ef5f30b

Browse files
committed
Add some more mypy checks
1 parent 9c8581d commit ef5f30b

File tree

9 files changed

+34
-23
lines changed

9 files changed

+34
-23
lines changed

.prospector.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ mypy:
1414
options:
1515
ignore-missing-imports: true
1616
follow-imports: skip
17+
check-untyped-defs: true
18+
disallow-any-generics: true
1719
disallow-untyped-defs: true
18-
#strict: true
20+
disallow-incomplete-defs: true
21+
disallow-untyped-decorators: true
22+
warn-unused-configs: true
23+
warn-unused-ignores: true
24+
warn-redundant-casts: true
25+
warn-return-any: true
26+
extra-checks: true
1927

2028
pylint:
2129
options:

prospector/config/__init__.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ def replace_deprecated_tool_names(self) -> list[str]:
9898

9999
def get_output_report(self) -> list[tuple[str, list[str]]]:
100100
# Get the output formatter
101+
output_report: list[tuple[str, list[str]]]
101102
if self.config.output_format is not None:
102103
output_report = self.config.output_format
103104
else:
104-
output_report = [(self.profile.output_format, self.profile.output_target)]
105+
output_report = [(self.profile.output_format, self.profile.output_target)] # type: ignore[list-item]
105106

106107
for index, report in enumerate(output_report):
107108
if not all(report):
@@ -262,7 +263,7 @@ def _determine_tool_runners(self, config: setoptconf.config.Configuration, profi
262263

263264
def _determine_ignores(
264265
self, config: setoptconf.config.Configuration, profile: ProspectorProfile, libraries: list[str]
265-
) -> list[re.Pattern]:
266+
) -> list[re.Pattern[str]]:
266267
# Grab ignore patterns from the options
267268
ignores = []
268269
for pattern in config.ignore_patterns + profile.ignore_patterns:
@@ -300,7 +301,7 @@ def get_summary_information(self) -> dict[str, Any]:
300301
}
301302

302303
def exit_with_zero_on_success(self) -> bool:
303-
return self.config.zero_exit
304+
return self.config.zero_exit # type: ignore[no-any-return]
304305

305306
def get_disabled_messages(self, tool_name: str) -> list[str]:
306307
return self.profile.get_disabled_messages(tool_name)
@@ -314,51 +315,51 @@ def tool_options(self, tool_name: str) -> dict[str, str]:
314315
tool = getattr(self.profile, tool_name, None)
315316
if tool is None:
316317
return {}
317-
return tool.get("options", {})
318+
return tool.get("options", {}) # type: ignore[no-any-return]
318319

319320
def external_config_location(self, tool_name: str) -> Optional[Path]:
320321
return getattr(self.config, "%s_config_file" % tool_name, None)
321322

322323
@property
323324
def die_on_tool_error(self) -> bool:
324-
return self.config.die_on_tool_error
325+
return self.config.die_on_tool_error # type: ignore[no-any-return]
325326

326327
@property
327328
def summary_only(self) -> bool:
328-
return self.config.summary_only
329+
return self.config.summary_only # type: ignore[no-any-return]
329330

330331
@property
331332
def messages_only(self) -> bool:
332-
return self.config.messages_only
333+
return self.config.messages_only # type: ignore[no-any-return]
333334

334335
@property
335336
def quiet(self) -> bool:
336-
return self.config.quiet
337+
return self.config.quiet # type: ignore[no-any-return]
337338

338339
@property
339340
def blending(self) -> bool:
340-
return self.config.blending
341+
return self.config.blending # type: ignore[no-any-return]
341342

342343
@property
343344
def absolute_paths(self) -> bool:
344-
return self.config.absolute_paths
345+
return self.config.absolute_paths # type: ignore[no-any-return]
345346

346347
@property
347348
def max_line_length(self) -> int:
348-
return self.config.max_line_length
349+
return self.config.max_line_length # type: ignore[no-any-return]
349350

350351
@property
351352
def include_tool_stdout(self) -> bool:
352-
return self.config.include_tool_stdout
353+
return self.config.include_tool_stdout # type: ignore[no-any-return]
353354

354355
@property
355356
def direct_tool_stdout(self) -> bool:
356-
return self.config.direct_tool_stdout
357+
return self.config.direct_tool_stdout # type: ignore[no-any-return]
357358

358359
@property
359360
def show_profile(self) -> bool:
360-
return self.config.show_profile
361+
return self.config.show_profile # type: ignore[no-any-return]
361362

362363
@property
363364
def legacy_tool_names(self) -> bool:
364-
return self.config.legacy_tool_names
365+
return self.config.legacy_tool_names # type: ignore[no-any-return]

prospector/finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FileFinder:
1818
is basically to know which files to pass to which tools to be inspected.
1919
"""
2020

21-
def __init__(self, *provided_paths: Path, exclusion_filters: Optional[Iterable[Callable]] = None):
21+
def __init__(self, *provided_paths: Path, exclusion_filters: Optional[Iterable[Callable[[Path], bool]]] = None):
2222
"""
2323
:param provided_paths:
2424
A list of Path objects to search for files and modules - can be either directories or files

prospector/profiles/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pathlib import Path
1+
from pathlib import Path # pylint: disable=cyclic-import
22

33
AUTO_LOADED_PROFILES = list(
44
Path(*parts)

prospector/profiles/profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_disabled_messages(self, tool_name: str) -> list[str]:
5858
return list(set(disable) - set(enable))
5959

6060
def is_tool_enabled(self, name: str) -> bool:
61-
enabled = getattr(self, name).get("run")
61+
enabled: Optional[bool] = getattr(self, name).get("run")
6262
if enabled is not None:
6363
return enabled
6464
# this is not explicitly enabled or disabled, so use the default

prospector/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def get_parser() -> argparse.ArgumentParser:
182182
"""
183183
manager = cfg.build_manager()
184184
source = cfg.build_command_line_source(prog="prospector", description=None)
185-
return source.build_parser(manager.settings, None)
185+
return source.build_parser(manager.settings, None) # type: ignore[no-any-return]
186186

187187

188188
def main() -> None:

prospector/tools/mypy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def format_message(message: str) -> Message:
4545
)
4646

4747

48-
def _run_in_subprocess(q: Queue, cmd: Callable[[list[str]], tuple[str, str]], paths: list[str]) -> None:
48+
def _run_in_subprocess(
49+
q: "Queue[tuple[str, str]]", cmd: Callable[[list[str]], tuple[str, str]], paths: list[str]
50+
) -> None:
4951
"""
5052
This function exists only to be called by multiprocessing.Process as using
5153
lambda is forbidden

prospector/tools/profile_validator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self) -> None:
6262
self.ignore_codes: list[str] = []
6363

6464
def configure(self, prospector_config: "ProspectorConfig", found_files: FileFinder) -> None:
65-
for profile in prospector_config.config.profiles: # type: ignore[attr-defined]
65+
for profile in prospector_config.config.profiles:
6666
self.to_check.add(profile)
6767

6868
self.ignore_codes = prospector_config.get_disabled_messages("profile-validator")

prospector/tools/pycodestyle/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def configure(
152152
def run(self, _: Any) -> list[Message]:
153153
assert self.checker is not None
154154
report = self.checker.check_files()
155-
return report.get_messages()
155+
return report.get_messages() # type: ignore[no-any-return]
156156

157157

158158
# Load pep8ext_naming into pycodestyle's configuration.

0 commit comments

Comments
 (0)