58
58
59
59
GENERIC_STUB_NOT_AT_RUNTIME_TYPES = {
60
60
'queue.Queue' ,
61
- 'os.PathLike ' ,
61
+ 'builtins._PathLike ' ,
62
62
} # type: Final
63
63
64
64
@@ -970,25 +970,27 @@ def tuple_type(self, items: List[Type]) -> TupleType:
970
970
971
971
972
972
def get_omitted_any (disallow_any : bool , fail : MsgCallback , note : MsgCallback ,
973
- typ : Type , fullname : Optional [str ] = None ,
973
+ orig_type : Type , fullname : Optional [str ] = None ,
974
974
unexpanded_type : Optional [Type ] = None ) -> AnyType :
975
975
if disallow_any :
976
976
if fullname in nongen_builtins :
977
+ typ = orig_type
977
978
# We use a dedicated error message for builtin generics (as the most common case).
978
979
alternative = nongen_builtins [fullname ]
979
980
fail (message_registry .IMPLICIT_GENERIC_ANY_BUILTIN .format (alternative ), typ ,
980
981
code = codes .TYPE_ARG )
981
982
else :
982
- typ = unexpanded_type or typ
983
+ typ = unexpanded_type or orig_type
983
984
type_str = typ .name if isinstance (typ , UnboundType ) else format_type_bare (typ )
984
985
985
986
fail (
986
- message_registry .BARE_GENERIC .format (
987
- quote_type_string (type_str )),
987
+ message_registry .BARE_GENERIC .format (quote_type_string (type_str )),
988
988
typ ,
989
989
code = codes .TYPE_ARG )
990
-
991
- if fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES :
990
+ if (
991
+ fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES
992
+ or orig_type .type .fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES
993
+ ):
992
994
# Recommend `from __future__ import annotations` or to put type in quotes
993
995
# (string literal escaping) for classes not generic at runtime
994
996
note (
@@ -1000,7 +1002,9 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback,
1000
1002
1001
1003
any_type = AnyType (TypeOfAny .from_error , line = typ .line , column = typ .column )
1002
1004
else :
1003
- any_type = AnyType (TypeOfAny .from_omitted_generics , line = typ .line , column = typ .column )
1005
+ any_type = AnyType (
1006
+ TypeOfAny .from_omitted_generics , line = orig_type .line , column = orig_type .column
1007
+ )
1004
1008
return any_type
1005
1009
1006
1010
0 commit comments