diff --git a/mypy/messages.py b/mypy/messages.py index 6b0760cd79c6f..40b0e7ee695a2 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -2700,7 +2700,7 @@ def format_literal_value(typ: LiteralType) -> str: if func.is_type_obj(): # The type of a type object type can be derived from the # return type (this always works). - return format(TypeType.make_normalized(erase_type(func.items[0].ret_type))) + return format(TypeType.make_normalized(func.items[0].ret_type)) elif isinstance(func, CallableType): if func.type_guard is not None: return_type = f"TypeGuard[{format(func.type_guard)}]" diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 08dfb3b54b3a2..5d6ad8e196313 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -1773,8 +1773,7 @@ T = TypeVar('T') class C(Generic[T]): def __init__(self) -> None: pass x = C # type: Callable[[], C[int]] -y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "Callable[[], int]") - +y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[T]]", variable has type "Callable[[], int]") -- Special cases -- ------------- diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index bec3a9a075933..560092ed1a43c 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -2488,7 +2488,7 @@ T = TypeVar('T') class C(Sequence[T], Generic[T]): pass C[0] = 0 [out] -main:4: error: Unsupported target for indexed assignment ("Type[C[Any]]") +main:4: error: Unsupported target for indexed assignment ("Type[C[T]]") main:4: error: Invalid type: try using Literal[0] instead? [case testNoCrashOnPartialMember] diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index 81b0066dbf810..7ac90d07e5047 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -2743,13 +2743,11 @@ T = TypeVar('T') class C(Generic[T]): pass -# TODO: Error message is confusing + C = C[int] # E: Cannot assign to a type \ - # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "Type[C[Any]]") + # E: Incompatible types in assignment (expression has type "Type[C[int]]", variable has type "Type[C[T]]") x: C reveal_type(x) # N: Revealed type is "__main__.C[Any]" -[out] -[out2] [case testNewAnalyzerClassVariableOrdering] def foo(x: str) -> None: pass diff --git a/test-data/unit/fine-grained-inspect.test b/test-data/unit/fine-grained-inspect.test index ed89f2f099f94..0e05769370a27 100644 --- a/test-data/unit/fine-grained-inspect.test +++ b/test-data/unit/fine-grained-inspect.test @@ -23,7 +23,7 @@ NameExpr -> "C[T]" MemberExpr -> "T" NameExpr -> "C[T]" MemberExpr -> "T" -12:5:12:5 -> "Type[foo.C[Any]]" +12:5:12:5 -> "Type[foo.C[builtins.int]]" 12:5:12:9 -> "foo.C[builtins.int]" 12:1:12:10 -> "builtins.int" CallExpr:12:5:12:9 -> "C[int]" diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 70003545754cf..66ceafb913703 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -823,7 +823,7 @@ class MyDDict(t.DefaultDict[int,T], t.Generic[T]): MyDDict(dict)['0'] MyDDict(dict)[0] [out] -_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected "Optional[Callable[[], str]]" +_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "Type[List[_T]]"; expected "Optional[Callable[[], str]]" _program.py:10: error: Invalid index type "str" for "defaultdict[int, str]"; expected type "int" _program.py:10: error: Incompatible types in assignment (expression has type "int", target has type "str") _program.py:20: error: Argument 1 to "tst" has incompatible type "defaultdict[str, List[Never]]"; expected "defaultdict[int, List[Never]]"