diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-09-09 23:05:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-09 23:05:00 +0200 |
commit | 0cc82c4c0de8771c1323cc2e183497d722ea5bfe (patch) | |
tree | 85ff551d96291e647a1b865ce13df9808ad3d4c5 | |
parent | ddde4fc074d0b4ae678f5111aafd0f54f3ddf409 (diff) | |
download | pylint-git-0cc82c4c0de8771c1323cc2e183497d722ea5bfe.tar.gz |
Turn on ``mypy`` strict mode 🎉 (#7448)
* Ignore subclasses of Any
* Add ignores for imported code and remove casts
* Add disables for uninferable return values
* Turn on ``mypy`` strict mode
30 files changed, 70 insertions, 72 deletions
diff --git a/pylint/checkers/base/name_checker/checker.py b/pylint/checkers/base/name_checker/checker.py index e4b061a17..0eded5f9b 100644 --- a/pylint/checkers/base/name_checker/checker.py +++ b/pylint/checkers/base/name_checker/checker.py @@ -337,7 +337,7 @@ class NameChecker(_BasicChecker): if len(groups[min_warnings]) > 1: by_line = sorted( groups[min_warnings], - key=lambda group: min( + key=lambda group: min( # type: ignore[no-any-return] warning[0].lineno for warning in group if warning[0].lineno is not None diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index 9e2b1b6ce..099b6897a 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -200,7 +200,7 @@ def _positional_parameters(method: nodes.FunctionDef) -> list[nodes.AssignName]: positional = method.args.args if method.is_bound() and method.type in {"classmethod", "method"}: positional = positional[1:] - return positional + return positional # type: ignore[no-any-return] class _DefaultMissing: @@ -841,7 +841,7 @@ a metaclass class method.", @cached_property def _dummy_rgx(self) -> Pattern[str]: - return self.linter.config.dummy_variables_rgx + return self.linter.config.dummy_variables_rgx # type: ignore[no-any-return] @only_required_for_messages( "abstract-method", @@ -1991,7 +1991,7 @@ a metaclass class method.", """ def is_abstract(method: nodes.FunctionDef) -> bool: - return method.is_abstract(pass_is_abstract=False) + return method.is_abstract(pass_is_abstract=False) # type: ignore[no-any-return] # check if this class abstract if class_is_abstract(node): diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index c97393bcc..a8e7fb1da 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -9,7 +9,7 @@ from __future__ import annotations import re from collections import defaultdict from collections.abc import Iterator -from typing import TYPE_CHECKING, List, cast +from typing import TYPE_CHECKING import astroid from astroid import nodes @@ -245,7 +245,7 @@ def _get_parents_iter( ``{A, B, C, D}`` -- both ``E`` and its ancestors are excluded. """ parents: set[nodes.ClassDef] = set() - to_explore = cast(List[nodes.ClassDef], list(node.ancestors(recurs=False))) + to_explore = list(node.ancestors(recurs=False)) while to_explore: parent = to_explore.pop() if parent.qname() in ignored_parents: diff --git a/pylint/checkers/modified_iterating_checker.py b/pylint/checkers/modified_iterating_checker.py index 62e887a95..979c8e00f 100644 --- a/pylint/checkers/modified_iterating_checker.py +++ b/pylint/checkers/modified_iterating_checker.py @@ -116,7 +116,7 @@ class ModifiedIterationChecker(checkers.BaseChecker): iter_obj: nodes.NodeNG, infer_val: nodes.List | nodes.Set, ) -> bool: - return (infer_val == utils.safe_infer(iter_obj)) and ( + return (infer_val == utils.safe_infer(iter_obj)) and ( # type: ignore[no-any-return] node.value.func.expr.name == iter_obj.name ) @@ -159,7 +159,7 @@ class ModifiedIterationChecker(checkers.BaseChecker): return False if infer_val != utils.safe_infer(iter_obj): return False - return node.targets[0].value.name == iter_obj.name + return node.targets[0].value.name == iter_obj.name # type: ignore[no-any-return] def _modified_iterating_set_cond( self, node: nodes.NodeNG, iter_obj: nodes.NodeNG diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index 32bee4711..ed1b7a938 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -147,7 +147,7 @@ def _is_part_of_with_items(node: nodes.Call) -> bool: if isinstance(current, nodes.With): items_start = current.items[0][0].lineno items_end = current.items[-1][0].tolineno - return items_start <= node.lineno <= items_end + return items_start <= node.lineno <= items_end # type: ignore[no-any-return] current = current.parent return False @@ -181,7 +181,7 @@ def _is_part_of_assignment_target(node: nodes.NodeNG) -> bool: return node in node.parent.targets if isinstance(node.parent, nodes.AugAssign): - return node == node.parent.target + return node == node.parent.target # type: ignore[no-any-return] if isinstance(node.parent, (nodes.Tuple, nodes.List)): return _is_part_of_assignment_target(node.parent) @@ -523,7 +523,7 @@ class RefactoringChecker(checkers.BaseTokenChecker): @cached_property def _dummy_rgx(self) -> Pattern[str]: - return self.linter.config.dummy_variables_rgx + return self.linter.config.dummy_variables_rgx # type: ignore[no-any-return] @staticmethod def _is_bool_const(node: nodes.Return | nodes.Assign) -> bool: @@ -748,13 +748,13 @@ class RefactoringChecker(checkers.BaseTokenChecker): @staticmethod def _type_and_name_are_equal(node_a: Any, node_b: Any) -> bool: if isinstance(node_a, nodes.Name) and isinstance(node_b, nodes.Name): - return node_a.name == node_b.name + return node_a.name == node_b.name # type: ignore[no-any-return] if isinstance(node_a, nodes.AssignName) and isinstance( node_b, nodes.AssignName ): - return node_a.name == node_b.name + return node_a.name == node_b.name # type: ignore[no-any-return] if isinstance(node_a, nodes.Const) and isinstance(node_b, nodes.Const): - return node_a.value == node_b.value + return node_a.value == node_b.value # type: ignore[no-any-return] return False def _is_dict_get_block(self, node: nodes.If) -> bool: diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 4def4b6c0..32d2394f8 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -585,7 +585,7 @@ def stripped_lines( line_begins_import = { lineno: all(is_import for _, is_import in node_is_import_group) for lineno, node_is_import_group in groupby( - node_is_import_by_lineno, key=lambda x: x[0] + node_is_import_by_lineno, key=lambda x: x[0] # type: ignore[no-any-return] ) } current_line_is_import = False diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py index d176bc08a..23209a2bc 100644 --- a/pylint/checkers/spelling.py +++ b/pylint/checkers/spelling.py @@ -75,14 +75,14 @@ else: instr = " To make it work, install the 'python-enchant' package." -class WordsWithDigitsFilter(Filter): +class WordsWithDigitsFilter(Filter): # type: ignore[misc] """Skips words with digits.""" def _skip(self, word: str) -> bool: return any(char.isdigit() for char in word) -class WordsWithUnderscores(Filter): +class WordsWithUnderscores(Filter): # type: ignore[misc] """Skips words with underscores. They are probably function parameter names. @@ -92,7 +92,7 @@ class WordsWithUnderscores(Filter): return "_" in word -class RegExFilter(Filter): +class RegExFilter(Filter): # type: ignore[misc] """Parent class for filters using regular expressions. This filter skips any words the match the expression @@ -128,7 +128,7 @@ class SphinxDirectives(RegExFilter): _pattern = re.compile(r"^(:([a-z]+)){1,2}:`([^`]+)(`)?") -class ForwardSlashChunker(Chunker): +class ForwardSlashChunker(Chunker): # type: ignore[misc] """This chunker allows splitting words like 'before/after' into 'before' and 'after'. """ diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index ed8878843..aabda2229 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -161,7 +161,7 @@ def _is_owner_ignored( def _node_names(node: SuccessfulInferenceResult) -> Iterable[str]: if not hasattr(node, "locals"): return [] - return node.locals.keys() + return node.locals.keys() # type: ignore[no-any-return] @_node_names.register(nodes.ClassDef) @@ -1001,7 +1001,7 @@ accessed. Python regular expressions are accepted.", @cached_property def _suggestion_mode(self) -> bool: - return self.linter.config.suggestion_mode + return self.linter.config.suggestion_mode # type: ignore[no-any-return] @cached_property def _compiled_generated_members(self) -> tuple[Pattern[str], ...]: @@ -1031,12 +1031,12 @@ accessed. Python regular expressions are accepted.", def _metaclass_name(metaclass: InferenceResult) -> str | None: # pylint: disable=unidiomatic-typecheck if isinstance(metaclass, (nodes.ClassDef, nodes.FunctionDef)): - return metaclass.name + return metaclass.name # type: ignore[no-any-return] if type(metaclass) is bases.Instance: # Really do mean type, not isinstance, since subclasses of bases.Instance # like Const or Dict should use metaclass.as_string below. return str(metaclass) - return metaclass.as_string() + return metaclass.as_string() # type: ignore[no-any-return] metaclass = node.declared_metaclass() if not metaclass: diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 0337e9f2d..1c66de687 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -277,7 +277,7 @@ SPECIAL_BUILTINS = ("__builtins__",) # '__path__', '__file__') def is_builtin_object(node: nodes.NodeNG) -> bool: """Returns True if the given node is an object from the __builtin__ module.""" - return node and node.root().name == "builtins" + return node and node.root().name == "builtins" # type: ignore[no-any-return] def is_builtin(name: str) -> bool: @@ -604,7 +604,7 @@ def split_format_field_names( format_string: str, ) -> tuple[str, Iterable[tuple[bool, str]]]: try: - return _string.formatter_field_name_split(format_string) + return _string.formatter_field_name_split(format_string) # type: ignore[no-any-return] except ValueError as e: raise IncompleteFormatString() from e @@ -788,7 +788,7 @@ def error_of_type( expected_errors = {stringify_error(error) for error in error_type} if not handler.type: return False - return handler.catch(expected_errors) + return handler.catch(expected_errors) # type: ignore[no-any-return] def decorated_with_property(node: nodes.FunctionDef) -> bool: @@ -1397,7 +1397,7 @@ def has_known_bases( ) -> bool: """Return true if all base classes of a class could be inferred.""" try: - return klass._all_bases_known + return klass._all_bases_known # type: ignore[no-any-return] except AttributeError: pass for base in klass.bases: @@ -1495,7 +1495,7 @@ def get_node_last_lineno(node: nodes.NodeNG) -> int: if getattr(node, "body", False): return get_node_last_lineno(node.body[-1]) # Not a compound statement - return node.lineno + return node.lineno # type: ignore[no-any-return] def is_postponed_evaluation_enabled(node: nodes.NodeNG) -> bool: @@ -1688,14 +1688,14 @@ def get_iterating_dictionary_name(node: nodes.For | nodes.Comprehension) -> str inferred = safe_infer(node.iter.func) if not isinstance(inferred, astroid.BoundMethod): return None - return node.iter.as_string().rpartition(".keys")[0] + return node.iter.as_string().rpartition(".keys")[0] # type: ignore[no-any-return] # Is it a dictionary? if isinstance(node.iter, (nodes.Name, nodes.Attribute)): inferred = safe_infer(node.iter) if not isinstance(inferred, nodes.Dict): return None - return node.iter.as_string() + return node.iter.as_string() # type: ignore[no-any-return] return None @@ -1731,7 +1731,7 @@ def get_import_name(importnode: ImportNode, modname: str | None) -> str | None: root = importnode.root() if isinstance(root, nodes.Module): try: - return root.relative_to_absolute_name(modname, level=importnode.level) + return root.relative_to_absolute_name(modname, level=importnode.level) # type: ignore[no-any-return] except TooManyLevelsError: return modname return modname @@ -1848,7 +1848,7 @@ def get_node_first_ancestor_of_type( """Return the first parent node that is any of the provided types (or None).""" for ancestor in node.node_ancestors(): if isinstance(ancestor, ancestor_type): - return ancestor + return ancestor # type: ignore[no-any-return] return None @@ -1907,7 +1907,7 @@ def is_typing_literal(node: nodes.NodeNG) -> bool: except IndexError: return False if isinstance(import_from, nodes.ImportFrom): - return ( + return ( # type: ignore[no-any-return] import_from.modname == "typing" and import_from.real_name(node.name) == "Literal" ) diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index da72a2bd3..8ba294e7d 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -215,7 +215,7 @@ def _detect_global_scope( # for annotations of function arguments, they'll have # their parent the Arguments node. if frame.parent_of(defframe): - return node.lineno < defframe.lineno + return node.lineno < defframe.lineno # type: ignore[no-any-return] if not isinstance(node.parent, (nodes.FunctionDef, nodes.Arguments)): return False elif any( @@ -249,7 +249,7 @@ def _detect_global_scope( return False # At this point, we are certain that frame and defframe share a scope # and the definition of the first depends on the second. - return frame.lineno < defframe.lineno + return frame.lineno < defframe.lineno # type: ignore[no-any-return] def _infer_name_module( @@ -257,7 +257,7 @@ def _infer_name_module( ) -> Generator[InferenceResult, None, None]: context = astroid.context.InferenceContext() context.lookupname = name - return node.infer(context, asname=False) + return node.infer(context, asname=False) # type: ignore[no-any-return] def _fix_dot_imports( @@ -303,7 +303,7 @@ def _fix_dot_imports( second_name = import_module_name if second_name and second_name not in names: names[second_name] = stmt - return sorted(names.items(), key=lambda a: a[1].fromlineno) + return sorted(names.items(), key=lambda a: a[1].fromlineno) # type: ignore[no-any-return] def _find_frame_imports(name: str, frame: nodes.LocalsDictNodeNG) -> bool: @@ -1780,7 +1780,7 @@ class VariablesChecker(BaseChecker): @cached_property def _ignored_modules(self) -> Iterable[str]: - return self.linter.config.ignored_modules + return self.linter.config.ignored_modules # type: ignore[no-any-return] @cached_property def _allow_global_unused_variables(self) -> bool: @@ -2663,7 +2663,7 @@ class VariablesChecker(BaseChecker): def _nodes_to_unpack(node: nodes.NodeNG) -> list[nodes.NodeNG] | None: """Return the list of values of the `Assign` node.""" if isinstance(node, (nodes.Tuple, nodes.List)): - return node.itered() + return node.itered() # type: ignore[no-any-return] if isinstance(node, astroid.Instance) and any( ancestor.qname() == "typing.NamedTuple" for ancestor in node.ancestors() ): diff --git a/pylint/config/configuration_mixin.py b/pylint/config/configuration_mixin.py index e92faa2d6..cdf6ad4fc 100644 --- a/pylint/config/configuration_mixin.py +++ b/pylint/config/configuration_mixin.py @@ -11,7 +11,7 @@ from pylint.config.options_provider_mixin import ( # type: ignore[attr-defined] ) -class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn): +class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn): # type: ignore[misc] """Basic mixin for simple configurations which don't need the manager / providers model. """ diff --git a/pylint/config/option.py b/pylint/config/option.py index 3bd812c0f..effd36f73 100644 --- a/pylint/config/option.py +++ b/pylint/config/option.py @@ -110,7 +110,7 @@ def _py_version_validator(_: Any, name: str, value: Any) -> tuple[int, int, int] raise optparse.OptionValueError( f"Invalid format for {name}, should be version string. E.g., '3.8'" ) from None - return value + return value # type: ignore[no-any-return] VALIDATORS: dict[str, Callable[[Any, str, Any], Any] | Callable[[Any], Any]] = { diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index d8f797b6c..46f0a2ac6 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -43,7 +43,7 @@ def get_setters_property_name(node: nodes.FunctionDef) -> str | None: and decorator.attrname == "setter" and isinstance(decorator.expr, nodes.Name) ): - return decorator.expr.name + return decorator.expr.name # type: ignore[no-any-return] return None diff --git a/pylint/extensions/code_style.py b/pylint/extensions/code_style.py index ef8aaea78..6acdb83d8 100644 --- a/pylint/extensions/code_style.py +++ b/pylint/extensions/code_style.py @@ -5,7 +5,7 @@ from __future__ import annotations import sys -from typing import TYPE_CHECKING, Tuple, Type, Union, cast +from typing import TYPE_CHECKING, Tuple, Type, cast from astroid import nodes @@ -164,13 +164,11 @@ class CodeStyleChecker(BaseChecker): if list_length == 0: return for _, dict_value in node.items[1:]: - dict_value = cast(Union[nodes.List, nodes.Tuple], dict_value) if len(dict_value.elts) != list_length: return # Make sure at least one list entry isn't a dict for _, dict_value in node.items: - dict_value = cast(Union[nodes.List, nodes.Tuple], dict_value) if all(isinstance(entry, nodes.Dict) for entry in dict_value.elts): return diff --git a/pylint/extensions/mccabe.py b/pylint/extensions/mccabe.py index e46bd5fbd..ea64d2ebf 100644 --- a/pylint/extensions/mccabe.py +++ b/pylint/extensions/mccabe.py @@ -45,13 +45,13 @@ _AppendableNodeT = TypeVar( ) -class PathGraph(Mccabe_PathGraph): +class PathGraph(Mccabe_PathGraph): # type: ignore[misc] def __init__(self, node: _SubGraphNodes | nodes.FunctionDef): super().__init__(name="", entity="", lineno=1) self.root = node -class PathGraphingAstVisitor(Mccabe_PathGraphingAstVisitor): +class PathGraphingAstVisitor(Mccabe_PathGraphingAstVisitor): # type: ignore[misc] def __init__(self) -> None: super().__init__() self._bottom_counter = 0 diff --git a/pylint/extensions/private_import.py b/pylint/extensions/private_import.py index 53e285ac3..61d37af37 100644 --- a/pylint/extensions/private_import.py +++ b/pylint/extensions/private_import.py @@ -195,7 +195,7 @@ class PrivateImportChecker(BaseChecker): """ if isinstance(node, nodes.Name) and node.name not in all_used_type_annotations: all_used_type_annotations[node.name] = True - return node.name + return node.name # type: ignore[no-any-return] if isinstance(node, nodes.Subscript): # e.g. Optional[List[str]] # slice is the next nested type self._populate_type_annotations_annotation( diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index 27d4bd812..91887cd92 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -18,7 +18,7 @@ def _modpath_from_file(filename: str, is_namespace: bool, path: list[str]) -> li def _is_package_cb(inner_path: str, parts: list[str]) -> bool: return modutils.check_modpath_has_init(inner_path, parts) or is_namespace - return modutils.modpath_from_file_with_callback( + return modutils.modpath_from_file_with_callback( # type: ignore[no-any-return] filename, path=path, is_package_cb=_is_package_cb ) diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 7fb696fdb..121d0d7f8 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -95,7 +95,7 @@ def _load_reporter_by_class(reporter_class: str) -> type[BaseReporter]: class_name = qname.split(".")[-1] klass = getattr(module, class_name) assert issubclass(klass, BaseReporter), f"{klass} is not a BaseReporter" - return klass + return klass # type: ignore[no-any-return] # Python Linter class ######################################################### diff --git a/pylint/pyreverse/diadefslib.py b/pylint/pyreverse/diadefslib.py index c6939e2a1..85b23052e 100644 --- a/pylint/pyreverse/diadefslib.py +++ b/pylint/pyreverse/diadefslib.py @@ -36,7 +36,7 @@ class DiaDefGenerator: title = node.name if self.module_names: title = f"{node.root().name}.{title}" - return title + return title # type: ignore[no-any-return] def _set_option(self, option: bool | None) -> bool: """Activate some options if not explicitly deactivated.""" @@ -70,7 +70,7 @@ class DiaDefGenerator: """True if builtins and not show_builtins.""" if self.config.show_builtin: return True - return node.root().name != "builtins" + return node.root().name != "builtins" # type: ignore[no-any-return] def add_class(self, node: nodes.ClassDef) -> None: """Visit one class and add it to diagram.""" diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 7b15bf816..a9dcd1c5e 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -143,7 +143,7 @@ class ClassDiagram(Figure, FilterMixIn): and not decorated_with_property(m) and self.show_attr(m.name) ] - return sorted(methods, key=lambda n: n.name) + return sorted(methods, key=lambda n: n.name) # type: ignore[no-any-return] def add_object(self, title: str, node: nodes.ClassDef) -> None: """Create a diagram object.""" diff --git a/pylint/pyreverse/utils.py b/pylint/pyreverse/utils.py index a1de38685..078bc1b7e 100644 --- a/pylint/pyreverse/utils.py +++ b/pylint/pyreverse/utils.py @@ -74,12 +74,12 @@ def get_visibility(name: str) -> str: def is_interface(node: nodes.ClassDef) -> bool: # bw compatibility - return node.type == "interface" + return node.type == "interface" # type: ignore[no-any-return] def is_exception(node: nodes.ClassDef) -> bool: # bw compatibility - return node.type == "exception" + return node.type == "exception" # type: ignore[no-any-return] # Helpers ##################################################################### @@ -170,9 +170,9 @@ class LocalsVisitor: def get_annotation_label(ann: nodes.Name | nodes.NodeNG) -> str: if isinstance(ann, nodes.Name) and ann.name is not None: - return ann.name + return ann.name # type: ignore[no-any-return] if isinstance(ann, nodes.NodeNG): - return ann.as_string() + return ann.as_string() # type: ignore[no-any-return] return "" diff --git a/pylint/pyreverse/writer.py b/pylint/pyreverse/writer.py index 12a76df9b..b19286a87 100644 --- a/pylint/pyreverse/writer.py +++ b/pylint/pyreverse/writer.py @@ -92,7 +92,7 @@ class DiagramWriter: def write_classes(self, diagram: ClassDiagram) -> None: """Write a class diagram.""" # sorted to get predictable (hence testable) results - for obj in sorted(diagram.objects, key=lambda x: x.title): + for obj in sorted(diagram.objects, key=lambda x: x.title): # type: ignore[no-any-return] obj.fig_id = obj.node.qname() type_ = NodeType.INTERFACE if obj.shape == "interface" else NodeType.CLASS self.printer.emit_node( diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index 0d3dbb0bf..d05f7e481 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -145,7 +145,7 @@ class LintModuleTest: self._runTest() def _should_be_skipped_due_to_version(self) -> bool: - return ( + return ( # type: ignore[no-any-return] sys.version_info < self._linter.config.min_pyver or sys.version_info > self._linter.config.max_pyver ) diff --git a/pylint/utils/file_state.py b/pylint/utils/file_state.py index 9624174ad..bf0bd58d6 100644 --- a/pylint/utils/file_state.py +++ b/pylint/utils/file_state.py @@ -292,4 +292,4 @@ class FileState: ) def get_effective_max_line_number(self) -> int | None: - return self._effective_max_line_number + return self._effective_max_line_number # type: ignore[no-any-return] diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index 6a4277642..8f5c3af17 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -431,5 +431,5 @@ class IsortDriver: def place_module(self, package: str) -> str: if HAS_ISORT_5: - return isort.api.place_module(package, self.isort5_config) - return self.isort4_obj.place_module(package) + return isort.api.place_module(package, self.isort5_config) # type: ignore[no-any-return] + return self.isort4_obj.place_module(package) # type: ignore[no-any-return] @@ -39,13 +39,13 @@ max-complexity=39 min_python_version = 3.7.2 [mypy] -no_implicit_optional = True scripts_are_modules = True warn_unused_ignores = True -disallow_any_generics = True show_error_codes = True enable_error_code = ignore-without-code -check_untyped_defs = True +strict = True +# TODO: Remove this once pytest has annotations +disallow_untyped_decorators = False [mypy-astroid.*] ignore_missing_imports = True diff --git a/tests/lint/test_pylinter.py b/tests/lint/test_pylinter.py index 5e2f20ff6..153c05065 100644 --- a/tests/lint/test_pylinter.py +++ b/tests/lint/test_pylinter.py @@ -30,7 +30,7 @@ def test_crash_in_file( out, err = capsys.readouterr() assert not out assert not err - files = tmpdir.listdir() + files = tmpdir.listdir() # type: ignore[no-untyped-call] assert len(files) == 1 assert "pylint-crash-20" in str(files[0]) assert any(m.symbol == "fatal" for m in linter.reporter.messages) @@ -53,7 +53,7 @@ def test_crash_during_linting( out, err = capsys.readouterr() assert not out assert not err - files = tmpdir.listdir() + files = tmpdir.listdir() # type: ignore[no-untyped-call] assert len(files) == 1 assert "pylint-crash-20" in str(files[0]) assert any(m.symbol == "astroid-error" for m in linter.reporter.messages) diff --git a/tests/reporters/unittest_json_reporter.py b/tests/reporters/unittest_json_reporter.py index a4a3d65d3..9104016ea 100644 --- a/tests/reporters/unittest_json_reporter.py +++ b/tests/reporters/unittest_json_reporter.py @@ -102,7 +102,7 @@ def get_linter_result(score: bool, message: dict[str, Any]) -> list[dict[str, An reporter.display_reports(EvaluationSection(expected_score_message)) reporter.display_messages(None) report_result = json.loads(output.getvalue()) - return report_result + return report_result # type: ignore[no-any-return] @pytest.mark.parametrize( diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index 27d083e9d..936de8fd6 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -67,10 +67,10 @@ def test_pylint_run_jobs_equal_zero_dont_crash_with_cpu_fraction( def _mock_open(*args: Any, **kwargs: Any) -> BufferedReader: if args[0] == "/sys/fs/cgroup/cpu/cpu.cfs_quota_us": - return mock_open(read_data=b"-1")(*args, **kwargs) + return mock_open(read_data=b"-1")(*args, **kwargs) # type: ignore[no-any-return] if args[0] == "/sys/fs/cgroup/cpu/cpu.shares": - return mock_open(read_data=b"2")(*args, **kwargs) - return builtin_open(*args, **kwargs) + return mock_open(read_data=b"2")(*args, **kwargs) # type: ignore[no-any-return] + return builtin_open(*args, **kwargs) # type: ignore[no-any-return] pathlib_path = pathlib.Path diff --git a/tests/test_self.py b/tests/test_self.py index 873bd2344..292a4b95d 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -518,7 +518,7 @@ class TestRunTC: @pytest.mark.parametrize("write_bpy_to_disk", [False, True]) def test_relative_imports(self, write_bpy_to_disk: bool, tmpdir: LocalPath) -> None: - a = tmpdir.join("a") + a = tmpdir.join("a") # type: ignore[no-untyped-call] b_code = textwrap.dedent( """ |