Skip to content

Commit 5d7cc62

Browse files
author
hauntsaninja
committed
fix for unbounded types
1 parent cc763b8 commit 5d7cc62

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

mypy/typeanal.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
GENERIC_STUB_NOT_AT_RUNTIME_TYPES = {
6060
'queue.Queue',
61-
'os.PathLike',
61+
'builtins._PathLike',
6262
} # type: Final
6363

6464

@@ -970,25 +970,27 @@ def tuple_type(self, items: List[Type]) -> TupleType:
970970

971971

972972
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,
974974
unexpanded_type: Optional[Type] = None) -> AnyType:
975975
if disallow_any:
976976
if fullname in nongen_builtins:
977+
typ = orig_type
977978
# We use a dedicated error message for builtin generics (as the most common case).
978979
alternative = nongen_builtins[fullname]
979980
fail(message_registry.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), typ,
980981
code=codes.TYPE_ARG)
981982
else:
982-
typ = unexpanded_type or typ
983+
typ = unexpanded_type or orig_type
983984
type_str = typ.name if isinstance(typ, UnboundType) else format_type_bare(typ)
984985

985986
fail(
986-
message_registry.BARE_GENERIC.format(
987-
quote_type_string(type_str)),
987+
message_registry.BARE_GENERIC.format(quote_type_string(type_str)),
988988
typ,
989989
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+
):
992994
# Recommend `from __future__ import annotations` or to put type in quotes
993995
# (string literal escaping) for classes not generic at runtime
994996
note(
@@ -1000,7 +1002,9 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback,
10001002

10011003
any_type = AnyType(TypeOfAny.from_error, line=typ.line, column=typ.column)
10021004
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+
)
10041008
return any_type
10051009

10061010

0 commit comments

Comments
 (0)