@@ -152,6 +152,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
152
152
elif fullname == 'typing.Tuple' :
153
153
if len (t .args ) == 0 and not t .empty_tuple_index :
154
154
# Bare 'Tuple' is same as 'tuple'
155
+ self .implicit_any ('Tuple without type args' , t )
155
156
return self .builtin_type ('builtins.tuple' )
156
157
if len (t .args ) == 2 and isinstance (t .args [1 ], EllipsisType ):
157
158
# Tuple[T, ...] (uniform, variable-length tuple)
@@ -174,6 +175,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
174
175
return self .analyze_callable_type (t )
175
176
elif fullname == 'typing.Type' :
176
177
if len (t .args ) == 0 :
178
+ self .implicit_any ('Type without type args' , t )
177
179
return TypeType (AnyType (), line = t .line )
178
180
if len (t .args ) != 1 :
179
181
self .fail ('Type[...] must have exactly one type argument' , t )
@@ -183,6 +185,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
183
185
if self .nesting_level > 0 :
184
186
self .fail ('Invalid type: ClassVar nested inside other type' , t )
185
187
if len (t .args ) == 0 :
188
+ self .implicit_any ('ClassVar without type args' , t )
186
189
return AnyType (line = t .line )
187
190
if len (t .args ) != 1 :
188
191
self .fail ('ClassVar[...] must have at most one type argument' , t )
@@ -202,6 +205,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
202
205
act_len = len (an_args )
203
206
if exp_len > 0 and act_len == 0 :
204
207
# Interpret bare Alias same as normal generic, i.e., Alias[Any, Any, ...]
208
+ self .implicit_any ('Generic type without type args' , t )
205
209
return self .replace_alias_tvars (override , all_vars , [AnyType ()] * exp_len ,
206
210
t .line , t .column )
207
211
if exp_len == 0 and act_len == 0 :
@@ -220,6 +224,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
220
224
# context. This is slightly problematic as it allows using the type 'Any'
221
225
# as a base class -- however, this will fail soon at runtime so the problem
222
226
# is pretty minor.
227
+ self .implicit_any ('Assigning value of type Any' , t )
223
228
return AnyType ()
224
229
# Allow unbound type variables when defining an alias
225
230
if not (self .aliasing and sym .kind == TVAR and
@@ -259,6 +264,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
259
264
fallback = instance )
260
265
return instance
261
266
else :
267
+ self .implicit_any ('Fallback' , t )
262
268
return AnyType ()
263
269
264
270
def get_type_var_names (self , tp : Type ) -> List [str ]:
@@ -374,6 +380,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
374
380
fallback = self .builtin_type ('builtins.function' )
375
381
if len (t .args ) == 0 :
376
382
# Callable (bare). Treat as Callable[..., Any].
383
+ self .implicit_any ('Callable without type args' , t )
377
384
ret = CallableType ([AnyType (), AnyType ()],
378
385
[nodes .ARG_STAR , nodes .ARG_STAR2 ],
379
386
[None , None ],
@@ -492,6 +499,10 @@ def builtin_type(self, fully_qualified_name: str, args: List[Type] = None) -> In
492
499
def tuple_type (self , items : List [Type ]) -> TupleType :
493
500
return TupleType (items , fallback = self .builtin_type ('builtins.tuple' , [AnyType ()]))
494
501
502
+ def implicit_any (self , details : str , t : Type ) -> None :
503
+ msg = 'Type Any created implicitly: ' + details
504
+ self .fail (msg , t , implicit_any = True ) # type: ignore
505
+
495
506
496
507
class TypeAnalyserPass3 (TypeVisitor [None ]):
497
508
"""Analyze type argument counts and values of generic types.
@@ -522,6 +533,8 @@ def visit_instance(self, t: Instance) -> None:
522
533
if len (t .args ) != len (info .type_vars ):
523
534
if len (t .args ) == 0 :
524
535
# Insert implicit 'Any' type arguments.
536
+ if t .type .fullname () not in ('typing.Generator' ):
537
+ self .implicit_any ('{} without type args' .format (t ), t )
525
538
t .args = [AnyType ()] * len (info .type_vars )
526
539
return
527
540
# Invalid number of type parameters.
@@ -624,6 +637,10 @@ def visit_partial_type(self, t: PartialType) -> None:
624
637
def visit_type_type (self , t : TypeType ) -> None :
625
638
pass
626
639
640
+ def implicit_any (self , details : str , t : Type ) -> None :
641
+ msg = 'Type Any created implicitly: ' + details
642
+ self .fail (msg , t , implicit_any = True ) # type: ignore
643
+
627
644
628
645
TypeVarList = List [Tuple [str , TypeVarExpr ]]
629
646
0 commit comments