diff --git a/mypy/typeanal.py b/mypy/typeanal.py index d17de6b7d88dc..7a7408d351e19 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -970,25 +970,28 @@ def tuple_type(self, items: List[Type]) -> TupleType: def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback, - typ: Type, fullname: Optional[str] = None, + orig_type: Type, fullname: Optional[str] = None, unexpanded_type: Optional[Type] = None) -> AnyType: if disallow_any: if fullname in nongen_builtins: + typ = orig_type # We use a dedicated error message for builtin generics (as the most common case). alternative = nongen_builtins[fullname] fail(message_registry.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), typ, code=codes.TYPE_ARG) else: - typ = unexpanded_type or typ + typ = unexpanded_type or orig_type type_str = typ.name if isinstance(typ, UnboundType) else format_type_bare(typ) fail( - message_registry.BARE_GENERIC.format( - quote_type_string(type_str)), + message_registry.BARE_GENERIC.format(quote_type_string(type_str)), typ, code=codes.TYPE_ARG) - - if fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES: + base_type = get_proper_type(orig_type) + base_fullname = ( + base_type.type.fullname if isinstance(base_type, Instance) else fullname + ) + if base_fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES: # Recommend `from __future__ import annotations` or to put type in quotes # (string literal escaping) for classes not generic at runtime note( @@ -1000,7 +1003,9 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback, any_type = AnyType(TypeOfAny.from_error, line=typ.line, column=typ.column) else: - any_type = AnyType(TypeOfAny.from_omitted_generics, line=typ.line, column=typ.column) + any_type = AnyType( + TypeOfAny.from_omitted_generics, line=orig_type.line, column=orig_type.column + ) return any_type diff --git a/mypy/typeshed b/mypy/typeshed index 27dfbf68aaffa..e3889c776e88d 160000 --- a/mypy/typeshed +++ b/mypy/typeshed @@ -1 +1 @@ -Subproject commit 27dfbf68aaffab4f1ded7dc1b96f6f82f536a09d +Subproject commit e3889c776e88d0116c161cf518af58aea90bba83 diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 04f9d3f0276e6..9d74bdc9a1bec 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -1099,7 +1099,7 @@ from queue import Queue p: PathLike q: Queue [out] -test.py:4: error: Missing type parameters for generic type "_PathLike" +test.py:4: error: Missing type parameters for generic type "PathLike" 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 test.py:5: error: Missing type parameters for generic type "Queue" 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