From 47d7cd31dc2720ce7095accf659e75179ea8d051 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 6 Feb 2023 15:48:39 +0000 Subject: [PATCH 1/2] Consistently use type-abstract error code --- mypy/messages.py | 4 +++- test-data/unit/check-errorcodes.test | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index 23b6f7c0e991..aefe65f8de09 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1787,7 +1787,9 @@ def bad_proto_variance( def concrete_only_assign(self, typ: Type, context: Context) -> None: self.fail( - f"Can only assign concrete classes to a variable of type {format_type(typ)}", context + f"Can only assign concrete classes to a variable of type {format_type(typ)}", + context, + code=codes.TYPE_ABSTRACT, ) def concrete_only_call(self, typ: Type, context: Context) -> None: diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 6e848e6a1e39..8bf12eca1f59 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -998,6 +998,11 @@ T = TypeVar("T") def test(tp: Type[T]) -> T: ... test(C) # E: Only concrete class can be given where "Type[C]" is expected [type-abstract] +class D(C): + @abc.abstractmethod + def bar(self) -> None: ... +cls: Type[C] = D # E: Can only assign concrete classes to a variable of type "Type[C]" [type-abstract] + [case testUncheckedAnnotationCodeShown] def f(): x: int = "no" # N: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked] From cc5dc5487d3237c97dbe13cd93b93e18deb2f438 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 6 Feb 2023 17:28:12 +0000 Subject: [PATCH 2/2] Add TYPE_ABSTRACT to dict of code migrations --- mypy/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/errors.py b/mypy/errors.py index 7cc0c5764861..ee1fa137dfe4 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -24,7 +24,7 @@ # Keep track of the original error code when the error code of a message is changed. # This is used to give notes about out-of-date "type: ignore" comments. -original_error_codes: Final = {codes.LITERAL_REQ: codes.MISC} +original_error_codes: Final = {codes.LITERAL_REQ: codes.MISC, codes.TYPE_ABSTRACT: codes.MISC} class ErrorInfo: