Skip to content

Commit 8941484

Browse files
committed
Don't erase type object args in diagnostics
Fixes #16875
1 parent 6d13d0d commit 8941484

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ def format_literal_value(typ: LiteralType) -> str:
27002700
if func.is_type_obj():
27012701
# The type of a type object type can be derived from the
27022702
# return type (this always works).
2703-
return format(TypeType.make_normalized(erase_type(func.items[0].ret_type)))
2703+
return format(TypeType.make_normalized(func.items[0].ret_type))
27042704
elif isinstance(func, CallableType):
27052705
if func.type_guard is not None:
27062706
return_type = f"TypeGuard[{format(func.type_guard)}]"

test-data/unit/check-generics.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,8 +1773,7 @@ T = TypeVar('T')
17731773
class C(Generic[T]):
17741774
def __init__(self) -> None: pass
17751775
x = C # type: Callable[[], C[int]]
1776-
y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "Callable[[], int]")
1777-
1776+
y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[T]]", variable has type "Callable[[], int]")
17781777

17791778
-- Special cases
17801779
-- -------------

test-data/unit/check-inference.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ T = TypeVar('T')
24882488
class C(Sequence[T], Generic[T]): pass
24892489
C[0] = 0
24902490
[out]
2491-
main:4: error: Unsupported target for indexed assignment ("Type[C[Any]]")
2491+
main:4: error: Unsupported target for indexed assignment ("Type[C[T]]")
24922492
main:4: error: Invalid type: try using Literal[0] instead?
24932493

24942494
[case testNoCrashOnPartialMember]

test-data/unit/check-newsemanal.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,13 +2743,11 @@ T = TypeVar('T')
27432743

27442744
class C(Generic[T]):
27452745
pass
2746-
# TODO: Error message is confusing
2746+
27472747
C = C[int] # E: Cannot assign to a type \
2748-
# E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "Type[C[Any]]")
2748+
# E: Incompatible types in assignment (expression has type "Type[C[int]]", variable has type "Type[C[T]]")
27492749
x: C
27502750
reveal_type(x) # N: Revealed type is "__main__.C[Any]"
2751-
[out]
2752-
[out2]
27532751

27542752
[case testNewAnalyzerClassVariableOrdering]
27552753
def foo(x: str) -> None: pass

test-data/unit/fine-grained-inspect.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NameExpr -> "C[T]"
2323
MemberExpr -> "T"
2424
NameExpr -> "C[T]"
2525
MemberExpr -> "T"
26-
12:5:12:5 -> "Type[foo.C[Any]]"
26+
12:5:12:5 -> "Type[foo.C[builtins.int]]"
2727
12:5:12:9 -> "foo.C[builtins.int]"
2828
12:1:12:10 -> "builtins.int"
2929
CallExpr:12:5:12:9 -> "C[int]"

0 commit comments

Comments
 (0)