Skip to content

Commit

Permalink
Add small bits of typing annotation (#4954)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored Sep 25, 2021
1 parent 087d77a commit ae4e39e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pylint/reporters/base_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +45,7 @@ def set_output(self, output: Optional[TextIO] = None) -> None:
)
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)

Expand Down
4 changes: 3 additions & 1 deletion pylint/testutils/tokenize_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
12 changes: 7 additions & 5 deletions pylint/utils/pragma_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +52,7 @@
)


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
Expand All @@ -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
Expand All @@ -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 = ""
Expand All @@ -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)
Expand Down

0 comments on commit ae4e39e

Please sign in to comment.