diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-09-25 06:23:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-25 06:23:32 +0200 |
commit | ae4e39e986acf73f78b52422c902bcd28cbd985f (patch) | |
tree | 8e6960eb531f225456e2afd9e049f034661b3351 /pylint | |
parent | 087d77adcd8455dbbbf6b43631d93abb2d1c5d67 (diff) | |
download | pylint-git-ae4e39e986acf73f78b52422c902bcd28cbd985f.tar.gz |
Add small bits of typing annotation (#4954)
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/reporters/base_reporter.py | 4 | ||||
-rw-r--r-- | pylint/testutils/tokenize_str.py | 4 | ||||
-rw-r--r-- | pylint/utils/pragma_parser.py | 12 |
3 files changed, 12 insertions, 8 deletions
diff --git a/pylint/reporters/base_reporter.py b/pylint/reporters/base_reporter.py index d2efc24eb..244935a6b 100644 --- a/pylint/reporters/base_reporter.py +++ b/pylint/reporters/base_reporter.py @@ -23,7 +23,7 @@ class BaseReporter: extension = "" - def __init__(self, output: Optional[TextIO] = None): + def __init__(self, output: Optional[TextIO] = None) -> None: self.linter: "PyLinter" self.section = 0 self.out: TextIO = output or sys.stdout @@ -45,7 +45,7 @@ class BaseReporter: ) self.out = output or sys.stdout - def writeln(self, string=""): + def writeln(self, string: str = "") -> None: """write a line in the output buffer""" print(string, file=self.out) diff --git a/pylint/testutils/tokenize_str.py b/pylint/testutils/tokenize_str.py index 16bfea8ab..2c4f31acb 100644 --- a/pylint/testutils/tokenize_str.py +++ b/pylint/testutils/tokenize_str.py @@ -3,7 +3,9 @@ import tokenize from io import StringIO +from tokenize import TokenInfo +from typing import List -def _tokenize_str(code): +def _tokenize_str(code: str) -> List[TokenInfo]: return list(tokenize.generate_tokens(StringIO(code).readline)) diff --git a/pylint/utils/pragma_parser.py b/pylint/utils/pragma_parser.py index cbff8b26a..f1c1c2224 100644 --- a/pylint/utils/pragma_parser.py +++ b/pylint/utils/pragma_parser.py @@ -3,7 +3,7 @@ import re from collections import namedtuple -from typing import Generator, List +from typing import Generator, List, Optional # Allow stopping after the first semicolon/hash encountered, # so that an option can be continued with the reasons @@ -52,7 +52,7 @@ TOK_REGEX = "|".join( ) -def emit_pragma_representer(action, messages): +def emit_pragma_representer(action: str, messages: List[str]) -> PragmaRepresenter: if not messages and action in MESSAGE_KEYWORDS: raise InvalidPragmaError( "The keyword is not followed by message identifier", action @@ -65,7 +65,7 @@ class PragmaParserError(Exception): A class for exceptions thrown by pragma_parser module """ - def __init__(self, message, token): + def __init__(self, message: str, token: str) -> None: """ :args message: explain the reason why the exception has been thrown :args token: token concerned by the exception @@ -88,7 +88,7 @@ class InvalidPragmaError(PragmaParserError): def parse_pragma(pylint_pragma: str) -> Generator[PragmaRepresenter, None, None]: - action = None + action: Optional[str] = None messages: List[str] = [] assignment_required = False previous_token = "" @@ -113,7 +113,9 @@ def parse_pragma(pylint_pragma: str) -> Generator[PragmaRepresenter, None, None] raise InvalidPragmaError("Missing keyword before assignment", "") assignment_required = False elif assignment_required: - raise InvalidPragmaError("The = sign is missing after the keyword", action) + raise InvalidPragmaError( + "The = sign is missing after the keyword", action or "" + ) elif kind == "KEYWORD": if action: yield emit_pragma_representer(action, messages) |