-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inference for overloaded __call__ with generic self #16053
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2f12b60
Fix inference for overloaded __call__ with generic self
hauntsaninja a2abbb6
undo lazy hack
hauntsaninja 98b4b30
Merge remote-tracking branch 'upstream/master' into generic-call
hauntsaninja d5431e1
regression test
hauntsaninja c36efdd
new, bad test
hauntsaninja 89fc492
fix for non-generic callable tuple subclasses
hauntsaninja 45a7851
Merge remote-tracking branch 'upstream/master' into generic-call
hauntsaninja 9a776cf
fix
hauntsaninja 844826c
check fallback args
hauntsaninja 8004705
unnecessary if
hauntsaninja 4499906
comment
hauntsaninja 54187d1
remove my fix for callable generic tuple subclasses
hauntsaninja 1d959c3
ilevkivskyi fix
hauntsaninja b3aa066
subtype fixes
hauntsaninja ca4c294
break
hauntsaninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
comment
- Loading branch information
commit 44999065054885c58ed7dbf5cb3fd2483c4a8c4c
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -466,10 +466,11 @@ def visit_instance(self, left: Instance) -> bool: | |
if all(isinstance(get_proper_type(a), AnyType) for a in mapped.args): | ||
return not self.proper_subtype | ||
if mapped.type.tuple_type: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This additional branch looks like a hack. We shouldn't need this. I think the real bug is that we are passing incomplete information when accessing --- a/mypy/checkexpr.py
+++ b/mypy/checkexpr.py
@@ -1476,6 +1476,7 @@ class ExpressionChecker(ExpressionVisitor[Type]):
callable_node: Expression | None = None,
callable_name: str | None = None,
object_type: Type | None = None,
+ original_type: Type | None = None,
) -> tuple[Type, Type]:
"""Type check a call.
@@ -1538,7 +1539,7 @@ class ExpressionChecker(ExpressionVisitor[Type]):
is_super=False,
is_operator=True,
msg=self.msg,
- original_type=callee,
+ original_type=original_type or callee,
chk=self.chk,
in_literal_context=self.is_literal_context(),
)
@@ -1579,6 +1580,7 @@ class ExpressionChecker(ExpressionVisitor[Type]):
callable_node,
callable_name,
object_type,
+ original_type=callee,
)
else:
return self.msg.not_callable(callee, context), AnyType(TypeOfAny.from_error) |
||
expanded = expand_type_by_instance(mapped.type.tuple_type, mapped) | ||
assert isinstance(expanded, TupleType) | ||
# similar to logic inside map_instance_to_supertype | ||
tuple_type = expand_type_by_instance(mapped.type.tuple_type, mapped) | ||
assert isinstance(tuple_type, TupleType) | ||
return self._is_subtype( | ||
expanded, right.copy_modified(fallback=expanded.partial_fallback) | ||
tuple_type, right.copy_modified(fallback=tuple_type.partial_fallback) | ||
) and self._is_subtype(left, mypy.typeops.tuple_fallback(right)) | ||
return False | ||
if isinstance(right, TypeVarTupleType): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should actually be combined with the
if
just above. I just realised that theif
I added is incomplete, in fact if all type argument are eitherAny
or*tuple[Any, ...]
we are still good. But currently we are only considering only plain*tuple[Any, ...]
or e.g.Any, Any, Any
, while missingAny, *tuple[Any, ...], Any
, which should be equally fine (note you don't need to check number of unpacks, it is already validated during semantic analyzis).Note this also equally applies to the equivalent special case for plain instances I added around line 538. You may fix that as well if you want while you are at it.