Skip to content

Commit 4323547

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

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

mypy/typeanal.py

Lines changed: 9 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,24 @@ 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 orig_type.type.fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES:
992991
# Recommend `from __future__ import annotations` or to put type in quotes
993992
# (string literal escaping) for classes not generic at runtime
994993
note(
@@ -1000,7 +999,9 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback,
1000999

10011000
any_type = AnyType(TypeOfAny.from_error, line=typ.line, column=typ.column)
10021001
else:
1003-
any_type = AnyType(TypeOfAny.from_omitted_generics, line=typ.line, column=typ.column)
1002+
any_type = AnyType(
1003+
TypeOfAny.from_omitted_generics, line=orig_type.line, column=orig_type.column
1004+
)
10041005
return any_type
10051006

10061007

0 commit comments

Comments
 (0)