33
44import re
55from 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
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
9090def 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