FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't erase type object args in diagnostics by hauntsaninja · Pull Request #18352 · python/mypy · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .test  (5) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion mypy/messages.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)}]"
Expand Down
3 changes: 1 addition & 2 deletions test-data/unit/check-generics.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- -------------
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-inference.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions test-data/unit/check-newsemanal.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained-inspect.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/pythoneval.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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]]"
Expand Down

Back | FazBrowse Home | New Git URL