10000 Restrict the number of errors shown when there are missing stubs by JukkaL · Pull Request #10579 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Restrict the number of errors shown when there are missing stubs #10579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make the limit configurable
  • Loading branch information
JukkaL committed Jun 4, 2021
commit ade5bb92b5bc4ee49e59373484c61e059d8fe3ab
8 changes: 8 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@ in error messages.

Show absolute paths to files.

.. option:: --soft-error-limit N

This flag will adjust the limit after which mypy will (sometimes)
disable reporting most additional errors. The limit only applies
if it seems likely that most of the remaining errors will not be
useful or they may be overly noisy. If ``N`` is negative, there is
no limit. The default limit is 200.


.. _incremental:

Expand Down
3 changes: 2 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def _build(sources: List[BuildSource],
lambda path: read_py_file(path, cached_read, options.python_version),
options.show_absolute_path,
options.enabled_error_codes,
options.disabled_error_codes)
options.disabled_error_codes,
options.many_errors_threshold)
plugin, snapshot = load_plugins(options, errors, stdout, extra_plugins)

# Add catch-all .gitignore to cache dir if we created it
Expand Down
4 changes: 4 additions & 0 deletions mypy/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
'html',
'txt',
'lineprecision'] # type: Final

# Threshold after which we sometimes filter out most errors to avoid very
# verbose output
MANY_ERRORS_THRESHOLD = 200 # type: Final
19 changes: 10 additions & 9 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
allowed_duplicates = ['@overload', 'Got:', 'Expected:'] # type: Final


# Threshold after which we may filter out most errors to avoid very
# verbose output
MANY_ERRORS_THRESHOLD = 200


class ErrorInfo:
"""Representation of a single error message."""

Expand Down Expand Up @@ -179,7 +174,8 @@ def __init__(self,
read_source: Optional[Callable[[str], Optional[List[str]]]] = None,
show_absolute_path: bool = False,
enabled_error_codes: Optional[Set[ErrorCode]] = None,
disabled_error_codes: Optional[Set[ErrorCode]] = None) -> None:
disabled_error_codes: Optional[Set[ErrorCode]] = None,
many_errors_threshold: int = -1) -> None:
self.show_error_context = show_error_context
self.show_column_numbers = show_column_numbers
self.show_error_codes = show_error_codes
Expand All @@ -189,6 +185,7 @@ def __init__(self,
self.read_source = read_source
self.enabled_error_codes = enabled_error_codes or set()
self.disabled_error_codes = disabled_error_codes or set()
self.many_errors_threshold = many_errors_threshold
self.initialize()

def initialize(self) -> None:
Expand All @@ -215,7 +212,8 @@ def copy(self) -> 'Errors':
self.read_source,
self.show_absolute_path,
self.enabled_error_codes,
self.disabled_error_codes)
self.disabled_error_codes,
self.many_errors_threshold)
new.file = self.file
new.import_ctx = self.import_ctx[:]
new.function_or_member = self.function_or_member[:]
Expand Down Expand Up @@ -382,9 +380,12 @@ def add_error_info(self, info: ErrorInfo) -> None:
self._add_error_info(file, info)

def has_many_errors(self) -> bool:
if len(self.error_info_map) >= MANY_ERRORS_THRESHOLD:
if self.many_errors_threshold < 0:
return False
if len(self.error_info_map) >= self.many_errors_threshold:
return True
if sum(len(errors) for errors in self.error_info_map.values()) >= MANY_ERRORS_THRESHOLD:
if sum(len(errors)
for errors in self.error_info_map.values()) >= self.many_errors_threshold:
return True
return False

Expand Down
2 changes: 2 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ def add_invertible_flag(flag: str,
add_invertible_flag('--show-absolute-path', default=False,
help="Show absolute paths to files",
group=error_group)
error_group.add_argument('--soft-error-limit', default=defaults.MANY_ERRORS_THRESHOLD,
type=int, dest="many_errors_threshold", help=argparse.SUPPRESS)

incremental_group = parser.add_argument_group(
title='Incremental mode',
Expand Down
4 changes: 4 additions & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def __init__(self) -> None:
self.show_absolute_path = False # type: bool
# Install missing stub packages if True
self.install_types = False
# When we encounter errors that may cause many additional errors,
# skip most errors after this many messages have been reported.
# -1 means unlimited.
self.many_errors_threshold = defaults.MANY_ERRORS_THRESHOLD

# To avoid breaking plugin compatibility, keep providing new_semantic_analyzer
@property
Expand Down
0