@@ -1015,6 +1015,10 @@ def fail(self, msg: str, line: int, column: int) -> None:
10151015 if self .errors :
10161016 self .errors .report (line , column , msg )
10171017
1018+ def note (self , msg : str , line : int , column : int ) -> None :
1019+ if self .errors :
1020+ self .errors .report (line , column , msg , severity = 'note' )
1021+
10181022 def visit_raw_str (self , s : str ) -> Type :
10191023 # An escape hatch that allows the AST walker in fastparse2 to
10201024 # directly hook into the Python 3.5 type converter in some cases
@@ -1031,12 +1035,19 @@ def translate_expr_list(self, l: Sequence[ast3.expr]) -> List[Type]:
10311035
10321036 def visit_Call (self , e : ast3 .Call ) -> Type :
10331037 # Parse the arg constructor
1034- if not isinstance (self .parent (), ast3 .List ):
1035- return self .generic_visit (e )
10361038 f = e .func
10371039 constructor = stringify_name (f )
1040+
1041+ if not isinstance (self .parent (), ast3 .List ):
1042+ self .fail (TYPE_COMMENT_AST_ERROR , self .line , e .col_offset )
1043+ if constructor :
1044+ self .note ("Suggestion: use {}[...] instead of {}(...)" .format (
1045+ constructor , constructor ),
1046+ self .line , e .col_offset )
1047+ return AnyType (TypeOfAny .from_error )
10381048 if not constructor :
10391049 self .fail ("Expected arg constructor name" , e .lineno , e .col_offset )
1050+
10401051 name = None # type: Optional[str]
10411052 default_type = AnyType (TypeOfAny .special_form )
10421053 typ = default_type # type: Type
0 commit comments