3
3
4
4
import re
5
5
from collections import namedtuple
6
- from typing import Generator , List
6
+ from typing import Generator , List , Optional
7
7
8
8
# Allow stopping after the first semicolon/hash encountered,
9
9
# so that an option can be continued with the reasons
52
52
)
53
53
54
54
55
- def emit_pragma_representer (action , messages ) :
55
+ def emit_pragma_representer (action : str , messages : List [ str ]) -> PragmaRepresenter :
56
56
if not messages and action in MESSAGE_KEYWORDS :
57
57
raise InvalidPragmaError (
58
58
"The keyword is not followed by message identifier" , action
@@ -65,7 +65,7 @@ class PragmaParserError(Exception):
65
65
A class for exceptions thrown by pragma_parser module
66
66
"""
67
67
68
- def __init__ (self , message , token ) :
68
+ def __init__ (self , message : str , token : str ) -> None :
69
69
"""
70
70
:args message: explain the reason why the exception has been thrown
71
71
:args token: token concerned by the exception
@@ -88,7 +88,7 @@ class InvalidPragmaError(PragmaParserError):
88
88
89
89
90
90
def parse_pragma (pylint_pragma : str ) -> Generator [PragmaRepresenter , None , None ]:
91
- action = None
91
+ action : Optional [ str ] = None
92
92
messages : List [str ] = []
93
93
assignment_required = False
94
94
previous_token = ""
@@ -113,7 +113,9 @@ def parse_pragma(pylint_pragma: str) -> Generator[PragmaRepresenter, None, None]
113
113
raise InvalidPragmaError ("Missing keyword before assignment" , "" )
114
114
assignment_required = False
115
115
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
+ )
117
119
elif kind == "KEYWORD" :
118
120
if action :
119
121
yield emit_pragma_representer (action , messages )
0 commit comments