@@ -137,6 +137,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
137
137
elif fullname == 'typing.Tuple' :
138
138
if len (t .args ) == 0 and not t .empty_tuple_index :
139
139
# Bare 'Tuple' is same as 'tuple'
140
+ self .implicit_any ('Tuple without type args' , t )
140
141
return self .builtin_type ('builtins.tuple' )
141
142
if len (t .args ) == 2 and isinstance (t .args [1 ], EllipsisType ):
142
143
# Tuple[T, ...] (uniform, variable-length tuple)
@@ -159,6 +160,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
159
160
return self .analyze_callable_type (t )
160
161
elif fullname == 'typing.Type' :
161
162
if len (t .args ) == 0 :
163
+ self .implicit_any ('Type without type args' , t )
162
164
return TypeType (AnyType (), line = t .line )
163
165
if len (t .args ) != 1 :
164
166
self .fail ('Type[...] must have exactly one type argument' , t )
@@ -168,6 +170,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
168
170
if self .nesting_level > 0 :
169
171
self .fail ('Invalid type: ClassVar nested inside other type' , t )
170
172
if len (t .args ) == 0 :
173
+ self .implicit_any ('ClassVar without type args' , t )
171
174
return AnyType (line = t .line )
172
175
if len (t .args ) != 1 :
173
176
self .fail ('ClassVar[...] must have at most one type argument' , t )
@@ -187,6 +190,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
187
190
act_len = len (an_args )
188
191
if exp_len > 0 and act_len == 0 :
189
192
# Interpret bare Alias same as normal generic, i.e., Alias[Any, Any, ...]
193
+ self .implicit_any ('Generic type without type args' , t )
190
194
return self .replace_alias_tvars (override , all_vars , [AnyType ()] * exp_len ,
191
F438
195
t .line , t .column )
192
196
if exp_len == 0 and act_len == 0 :
@@ -205,6 +209,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
205
209
# context. This is slightly problematic as it allows using the type 'Any'
206
210
# as a base class -- however, this will fail soon at runtime so the problem
207
211
# is pretty minor.
212
+ self .implicit_any ('Assigning value of type Any' , t )
208
213
return AnyType ()
209
214
# Allow unbound type variables when defining an alias
210
215
if not (self .aliasing and sym .kind == UNBOUND_TVAR ):
@@ -243,6 +248,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
243
248
fallback = instance )
244
249
return instance
245
250
else :
251
+ self .implicit_any ('Fallback' , t )
246
252
return AnyType ()
247
253
248
254
def get_type_var_names (self , tp : Type ) -> List [str ]:
@@ -366,6 +372,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
366
372
fallback = self .builtin_type ('builtins.function' )
367
373
if len (t .args ) == 0 :
368
374
# Callable (bare). Treat as Callable[..., Any].
375
+ self .implicit_any ('Callable without type args' , t )
369
376
return CallableType ([AnyType (), AnyType ()],
370
377
[nodes .ARG_STAR , nodes .ARG_STAR2 ],
371
378
[None , None ],
@@ -429,6 +436,10 @@ def builtin_type(self, fully_qualified_name: str, args: List[Type] = None) -> In
429
436
def tuple_type (self , items : List [Type ]) -> TupleType :
430
437
return TupleType (items , fallback = self .builtin_type ('builtins.tuple' , [AnyType ()]))
431
438
439
+ def implicit_any (self , details : str , t : Type ) -> None :
440
+ msg = 'Type Any created implicitly: ' + details
441
+ self .fail (msg , t , implicit_any = True ) # type: ignore
442
+
432
443
433
444
class TypeAnalyserPass3 (TypeVisitor [None ]):
434
445
"""Analyze type argument counts and values of generic types.
@@ -459,6 +470,8 @@ def visit_instance(self, t: Instance) -> None:
459
470
if len (t .args ) != len (info .type_vars ):
460
471
if len (t .args ) == 0 :
461
472
# Insert implicit 'Any' type arguments.
473
+ if t .type .fullname () not in ('typing.Generator' ):
474
+ self .implicit_any ('{} without type args' .format (t ), t )
462
475
t .args = [AnyType ()] * len (info .type_vars )
463
476
return
464
477
# Invalid number of type parameters.
@@ -561,6 +574,10 @@ def visit_partial_type(self, t: PartialType) -> None:
561
574
def visit_type_type (self , t : TypeType ) -> None :
562
575
pass
563
576
577
+ def implicit_any (self , details : str , t : Type ) -> None :
578
+ msg = 'Type Any created implicitly: ' + details
579
+ self .fail (msg , t , implicit_any = True ) # type: ignore
580
+
564
581
565
582
def make_optional_type (t : Type ) -> Type :
566
583
"""Return the type corresponding to Optional[t].
0 commit comments