Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Consistently use type-abstract error code
  • Loading branch information
ilevkivskyi committed Feb 6, 2023
commit 47d7cd31dc2720ce7095accf659e75179ea8d051
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