Skip to content

Commit 6309d21

Browse files
committed
Add small bits of typing annotation
1 parent 1e675ab commit 6309d21

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

pylint/reporters/base_reporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BaseReporter:
2323

2424
extension = ""
2525

26-
def __init__(self, output: Optional[TextIO] = None):
26+
def __init__(self, output: Optional[TextIO] = None) -> None:
2727
self.linter: "PyLinter"
2828
self.section = 0
2929
self.out: TextIO = output or sys.stdout
@@ -45,7 +45,7 @@ def set_output(self, output: Optional[TextIO] = None) -> None:
4545
)
4646
self.out = output or sys.stdout
4747

48-
def writeln(self, string=""):
48+
def writeln(self, string: str = "") -> None:
4949
"""write a line in the output buffer"""
5050
print(string, file=self.out)
5151

pylint/testutils/tokenize_str.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import tokenize
55
from io import StringIO
6+
from tokenize import TokenInfo
7+
from typing import List
68

79

8-
def _tokenize_str(code):
10+
def _tokenize_str(code: str) -> List[TokenInfo]:
911
return list(tokenize.generate_tokens(StringIO(code).readline))

pylint/utils/pragma_parser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import re
55
from collections import namedtuple
6-
from typing import Generator, List
6+
from typing import Generator, List, Optional
77

88
# Allow stopping after the first semicolon/hash encountered,
99
# so that an option can be continued with the reasons
@@ -52,7 +52,7 @@
5252
)
5353

5454

55-
def emit_pragma_representer(action, messages):
55+
def emit_pragma_representer(action: str, messages: List[str]) -> PragmaRepresenter:
5656
if not messages and action in MESSAGE_KEYWORDS:
5757
raise InvalidPragmaError(
5858
"The keyword is not followed by message identifier", action
@@ -65,7 +65,7 @@ class PragmaParserError(Exception):
6565
A class for exceptions thrown by pragma_parser module
6666
"""
6767

68-
def __init__(self, message, token):
68+
def __init__(self, message: str, token: str) -> None:
6969
"""
7070
:args message: explain the reason why the exception has been thrown
7171
:args token: token concerned by the exception
@@ -88,7 +88,7 @@ class InvalidPragmaError(PragmaParserError):
8888

8989

9090
def parse_pragma(pylint_pragma: str) -> Generator[PragmaRepresenter, None, None]:
91-
action = None
91+
action: Optional[str] = None
9292
messages: List[str] = []
9393
assignment_required = False
9494
previous_token = ""
@@ -113,7 +113,9 @@ def parse_pragma(pylint_pragma: str) -> Generator[PragmaRepresenter, None, None]
113113
raise InvalidPragmaError("Missing keyword before assignment", "")
114114
assignment_required = False
115115
elif assignment_required:
116-
raise InvalidPragmaError("The = sign is missing after the keyword", action)
116+
raise InvalidPragmaError(
117+
"The = sign is missing after the keyword", action or ""
118+
)
117119
elif kind == "KEYWORD":
118120
if action:
119121
yield emit_pragma_representer(action, messages)

0 commit comments

Comments
 (0)