diff --git a/mypy/errors.py b/mypy/errors.py index 7cc0c5764861e..ee1fa137dfe4d 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: diff --git a/mypy/messages.py b/mypy/messages.py index 23b6f7c0e9913..aefe65f8de094 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 6e848e6a1e395..8bf12eca1f59a 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]