Skip to content

Commit

Permalink
WIP: Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Sep 15, 2021
1 parent 7680887 commit 8a4ac63
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
List,
NamedTuple,
NewType,
Optional,
Set,
TextIO,
Tuple,
Expand Down Expand Up @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions pylint/extensions/code_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
6 changes: 3 additions & 3 deletions pylint/extensions/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions pylint/reporters/base_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] = []
Expand Down Expand Up @@ -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."""
2 changes: 1 addition & 1 deletion pylint/reporters/multi_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pylint/reporters/ureports/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions pylint/testutils/lint_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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", "<lambda>"))
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 8a4ac63

Please sign in to comment.