From cc763b8884a674754d40c6e322002e8f3a978145 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 30 Sep 2020 10:06:50 -0700 Subject: [PATCH 1/3] Update tests for PathLike type alias As a result of https://github.com/python/typeshed/pull/4586 --- mypy/typeanal.py | 2 +- mypy/typeshed | 2 +- test-data/unit/cmdline.test | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index d17de6b7d88dc..fa94b6ec5eb53 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -58,7 +58,7 @@ GENERIC_STUB_NOT_AT_RUNTIME_TYPES = { 'queue.Queue', - 'builtins._PathLike', + 'os.PathLike', } # type: Final 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 From 4323547d40cbc916985f96c3b949982630d65701 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 30 Sep 2020 11:06:35 -0700 Subject: [PATCH 2/3] fix for unbounded types --- mypy/typeanal.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index fa94b6ec5eb53..a077df1c5b67b 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -58,7 +58,7 @@ GENERIC_STUB_NOT_AT_RUNTIME_TYPES = { 'queue.Queue', - 'os.PathLike', + 'builtins._PathLike', } # type: Final @@ -970,25 +970,24 @@ 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: + if orig_type.type.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 +999,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 From 1dc6e263b9d3b1535590f1dbfb3588e48e4f4b5e Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 30 Sep 2020 11:36:01 -0700 Subject: [PATCH 3/3] fix type error --- mypy/typeanal.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index a077df1c5b67b..7a7408d351e19 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -987,7 +987,11 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback, message_registry.BARE_GENERIC.format(quote_type_string(type_str)), typ, code=codes.TYPE_ARG) - if orig_type.type.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(