Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing for ./pylint, batch 1 #4954

Merged
merged 1 commit into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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