Skip to content

Commit b884a39

Browse files
authored
Fix runtime not generic note for type aliases, update for PathLike (#9512)
As a result of python/typeshed#4586 Co-authored-by: hauntsaninja <>
1 parent 3a590b9 commit b884a39

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

mypy/typeanal.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,25 +970,28 @@ 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+
base_type = get_proper_type(orig_type)
991+
base_fullname = (
992+
base_type.type.fullname if isinstance(base_type, Instance) else fullname
993+
)
994+
if base_fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES:
992995
# Recommend `from __future__ import annotations` or to put type in quotes
993996
# (string literal escaping) for classes not generic at runtime
994997
note(
@@ -1000,7 +1003,9 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback,
10001003

10011004
any_type = AnyType(TypeOfAny.from_error, line=typ.line, column=typ.column)
10021005
else:
1003-
any_type = AnyType(TypeOfAny.from_omitted_generics, line=typ.line, column=typ.column)
1006+
any_type = AnyType(
1007+
TypeOfAny.from_omitted_generics, line=orig_type.line, column=orig_type.column
1008+
)
10041009
return any_type
10051010

10061011

test-data/unit/cmdline.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ from queue import Queue
10991099
p: PathLike
11001100
q: Queue
11011101
[out]
1102-
test.py:4: error: Missing type parameters for generic type "_PathLike"
1102+
test.py:4: error: Missing type parameters for generic type "PathLike"
11031103
test.py:4: note: Subscripting classes that are not generic at runtime may require escaping, see https://mypy.readthedocs.io/en/latest/common_issues.html#not-generic-runtime
11041104
test.py:5: error: Missing type parameters for generic type "Queue"
11051105
test.py:5: note: Subscripting classes that are not generic at runtime may require escaping, see https://mypy.readthedocs.io/en/latest/common_issues.html#not-generic-runtime

0 commit comments

Comments
 (0)