Skip to content

Commit 44bf7e5

Browse files
authored
Don't erase type object args in diagnostics (#18352)
Fixes #16875
1 parent 670f486 commit 44bf7e5

File tree

6 files changed

+7
-10
lines changed

6 files changed

+7
-10
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]"

test-data/unit/pythoneval.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class MyDDict(t.DefaultDict[int,T], t.Generic[T]):
823823
MyDDict(dict)['0']
824824
MyDDict(dict)[0]
825825
[out]
826-
_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected "Optional[Callable[[], str]]"
826+
_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "Type[List[_T]]"; expected "Optional[Callable[[], str]]"
827827
_program.py:10: error: Invalid index type "str" for "defaultdict[int, str]"; expected type "int"
828828
_program.py:10: error: Incompatible types in assignment (expression has type "int", target has type "str")
829829
_program.py:20: error: Argument 1 to "tst" has incompatible type "defaultdict[str, List[Never]]"; expected "defaultdict[int, List[Never]]"

0 commit comments

Comments
 (0)