@@ -1016,6 +1016,10 @@ def fail(self, msg: str, line: int, column: int) -> None:
1016
1016
if self .errors :
1017
1017
self .errors .report (line , column , msg , blocker = True )
1018
1018
1019
+ def note (self , msg : str , line : int , column : int ) -> None :
1020
+ if self .errors :
1021
+ self .errors .report (line , column , msg , severity = 'note' )
1022
+
1019
1023
def visit_raw_str (self , s : str ) -> Type :
1020
1024
# An escape hatch that allows the AST walker in fastparse2 to
1021
1025
# directly hook into the Python 3.5 type converter in some cases
@@ -1032,12 +1036,19 @@ def translate_expr_list(self, l: Sequence[ast3.expr]) -> List[Type]:
1032
1036
1033
1037
def visit_Call (self , e : ast3 .Call ) -> Type :
1034
1038
# Parse the arg constructor
1035
- if not isinstance (self .parent (), ast3 .List ):
1036
- return self .generic_visit (e )
1037
1039
f = e .func
1038
1040
constructor = stringify_name (f )
1041
+
1042
+ if not isinstance (self .parent (), ast3 .List ):
1043
+ self .fail (TYPE_COMMENT_AST_ERROR , self .line , e .col_offset )
1044
+ if constructor :
1045
+ self .note ("Suggestion: use {}[...] instead of {}(...)" .format (
1046
+ constructor , constructor ),
1047
+ self .line , e .col_offset )
1048
+ return AnyType (TypeOfAny .from_error )
1039
1049
if not constructor :
1040
1050
self .fail ("Expected arg constructor name" , e .lineno , e .col_offset )
1051
+
1041
1052
name = None # type: Optional[str]
1042
1053
default_type = AnyType (TypeOfAny .special_form )
1043
1054
typ = default_type # type: Type
0 commit comments