Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently use type-abstract error code #14619

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down