From 8a4ac6311a34a34e27fd4b6d7de919318b1f5f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Wed, 15 Sep 2021 20:40:58 +0200 Subject: [PATCH] WIP: Small changes --- pylint/checkers/similar.py | 3 +-- pylint/extensions/code_style.py | 4 ++-- pylint/extensions/docparams.py | 6 +++--- pylint/reporters/base_reporter.py | 8 ++++---- pylint/reporters/multi_reporter.py | 2 +- pylint/reporters/ureports/nodes.py | 6 ++++++ pylint/testutils/lint_module_test.py | 4 ++-- pylint/utils/utils.py | 9 ++++----- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 414ca6aa795..345aee8350e 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -61,7 +61,6 @@ List, NamedTuple, NewType, - Optional, Set, TextIO, Tuple, @@ -378,7 +377,7 @@ def __init__( def append_stream( self, streamid: str, - stream: Union[BufferedReader, BytesIO, TextIO], + stream: Union[BufferedReader, BytesIO], encoding=None, ) -> None: """append a file to search for similarities""" diff --git a/pylint/extensions/code_style.py b/pylint/extensions/code_style.py index 1fe920a63d7..42681d379ce 100644 --- a/pylint/extensions/code_style.py +++ b/pylint/extensions/code_style.py @@ -78,8 +78,8 @@ def __init__(self, linter: PyLinter) -> None: def open(self) -> None: py_version = get_global_option(self, "py-version") - self._py38_plus: Tuple[int, int] = py_version >= (3, 8) - self._max_length: int = ( # type: ignore + self._py38_plus = py_version >= (3, 8) + self._max_length: int = ( self.config.max_line_length_suggestions or get_global_option(self, "max-line-length") ) diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py index bcd32d324cd..c3a1998b691 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -222,8 +222,8 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None: # skip functions smaller than 'docstring-min-length' lines = checker_utils.get_node_last_lineno(node) - node.lineno - max_lines: int = get_global_option(self, "docstring-min-length") # type: ignore - if max_lines > -1 and lines < max_lines: # type: ignore # This option is always an int. Refactor necessary for mypy + max_lines: int = get_global_option(self, "docstring-min-length") + if max_lines > -1 and lines < max_lines: return self.check_functiondef_params(node, node_doc) @@ -529,7 +529,7 @@ class constructor. # if isinstance(ignored_argument_names, re.Pattern) # and ignored_argument_names.match(arg) # Add the above code after dropping support for Python==3.6 and remove type: ignore - if ignored_argument_names.match(arg) # type: ignore + if ignored_argument_names.match(arg) } if arguments_node.vararg is not None: diff --git a/pylint/reporters/base_reporter.py b/pylint/reporters/base_reporter.py index 1fc8b1b380d..0658fd70512 100644 --- a/pylint/reporters/base_reporter.py +++ b/pylint/reporters/base_reporter.py @@ -3,9 +3,9 @@ import os import sys -from io import StringIO +from io import IOBase, StringIO from pathlib import PosixPath -from typing import TYPE_CHECKING, Any, Dict, List, Optional, TextIO, Union +from typing import TYPE_CHECKING, Any, List, Mapping, Optional, TextIO, Union from pylint.message import Message from pylint.reporters.ureports.nodes import BaseLayout, EvaluationSection, Section, Text @@ -25,7 +25,7 @@ class BaseReporter: def __init__(self, output: Optional[StringIO] = None) -> None: self.linter: Optional["PyLinter"] = None self.section = 0 - self.out: Optional[Union[TextIO, StringIO]] = None + self.out: Union[TextIO, IOBase] self.out_encoding = None self.set_output(output) self.messages: List[Message] = [] @@ -80,6 +80,6 @@ def on_set_current_module( """Hook called when a module starts to be analysed.""" def on_close( - self, stats: Optional[Dict[str, Any]], previous_stats: Dict[str, Any] + self, stats: Optional[Mapping[str, Any]], previous_stats: Mapping[str, Any] ) -> None: """Hook called when a module finished analyzing.""" diff --git a/pylint/reporters/multi_reporter.py b/pylint/reporters/multi_reporter.py index 1fa743403b1..a3041ccae93 100644 --- a/pylint/reporters/multi_reporter.py +++ b/pylint/reporters/multi_reporter.py @@ -4,7 +4,7 @@ import os from pathlib import PosixPath -from typing import IO, Any, AnyStr, Callable, List, Optional, Union +from typing import IO, Any, AnyStr, Callable, List, Mapping, Optional, Union from pylint.interfaces import IReporter from pylint.message import Message diff --git a/pylint/reporters/ureports/nodes.py b/pylint/reporters/ureports/nodes.py index d02914530b8..bc7691e3efa 100644 --- a/pylint/reporters/ureports/nodes.py +++ b/pylint/reporters/ureports/nodes.py @@ -42,7 +42,13 @@ def insert(self, index, child): self.children.insert(index, child) child.parent = self +<<<<<<< Updated upstream def accept(self, visitor: Union["BaseWriter", "TextWriter"], *args: Any, **kwargs: Any) -> Optional[Any]: +======= + def accept( + self, visitor: Union["BaseWriter", "TextWriter"], *args: Any, **kwargs: Any + ) -> Optional[Any]: +>>>>>>> Stashed changes func = getattr(visitor, f"visit_{self.visitor_name}") return func(self, *args, **kwargs) diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index a5f35cf8ce7..ca4e81a3c7a 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -7,7 +7,7 @@ import sys from collections import Counter from io import StringIO, TextIOWrapper -from typing import Dict, List, Optional, TextIO, Tuple, Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Dict, List, Optional, TextIO, Tuple, Union import pytest from _pytest.config import Config @@ -91,7 +91,7 @@ def __str__(self): return f"{self._test_file.base} ({self.__class__.__module__}.{self.__class__.__name__})" @staticmethod - def get_expected_messages(stream: TextIOWrapper) -> "CounterType[Tuple[int, str]]": + def get_expected_messages(stream: TextIO) -> "CounterType[Tuple[int, str]]": """Parses a file and get expected messages. :param stream: File-like input stream. diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index fd71939a6b2..33e0a781ceb 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -34,8 +34,7 @@ overload, ) -from astroid import Module, modutils, nodes -from astroid.nodes import Module, NodeNG +from astroid import modutils, nodes from pylint.constants import PY_EXTS @@ -103,12 +102,12 @@ def diff_string(old, new): return diff_str -def get_module_and_frameid(node: NodeNG) -> Tuple[str, str]: +def get_module_and_frameid(node: nodes.NodeNG) -> Tuple[str, str]: """return the module name and the frame id in the module""" frame = node.frame() module, obj = "", [] while frame: - if isinstance(frame, Module): + if isinstance(frame, nodes.Module): module = frame.name else: obj.append(getattr(frame, "name", "")) @@ -164,7 +163,7 @@ def decoding_stream( reader_cls = codecs.getreader(encoding or sys.getdefaultencoding()) except LookupError: reader_cls = codecs.getreader(sys.getdefaultencoding()) - return reader_cls(stream, errors) # type: ignore # This fails because of incorrect typing in encodings + return reader_cls(stream, errors) def tokenize_module(node: nodes.Module) -> List[tokenize.TokenInfo]: