summaryrefslogtreecommitdiff
path: root/pylint/utils/pragma_parser.py
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-09-25 06:23:32 +0200
committerGitHub <noreply@github.com>2021-09-25 06:23:32 +0200
commitae4e39e986acf73f78b52422c902bcd28cbd985f (patch)
tree8e6960eb531f225456e2afd9e049f034661b3351 /pylint/utils/pragma_parser.py
parent087d77adcd8455dbbbf6b43631d93abb2d1c5d67 (diff)
downloadpylint-git-ae4e39e986acf73f78b52422c902bcd28cbd985f.tar.gz
Add small bits of typing annotation (#4954)
Diffstat (limited to 'pylint/utils/pragma_parser.py')
-rw-r--r--pylint/utils/pragma_parser.py12
1 files changed, 7 insertions, 5 deletions
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)