Skip to content

Fix crash related with __getattr__ and __call__ #7446

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add forgotten changes
  • Loading branch information
onlined committed Sep 3, 2019
commit a64852cc87dcfad8fa9cd1ca1c2caa631c1ffb7d
6 changes: 3 additions & 3 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3801,12 +3801,12 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
isinstance(subtype, (Instance, TupleType, TypedDictType))):
self.msg.report_protocol_problems(subtype, supertype, context, code=code)
if isinstance(supertype, CallableType) and isinstance(subtype, Instance):
call = find_member('__call__', subtype, subtype)
call = find_member('__call__', subtype, subtype, is_operator=True)
if call:
self.msg.note_call(subtype, call, context, code=code)
if isinstance(subtype, (CallableType, Overloaded)) and isinstance(supertype, Instance):
if supertype.type.is_protocol and supertype.type.protocol_members == ['__call__']:
call = find_member('__call__', supertype, subtype)
call = find_member('__call__', supertype, subtype, is_operator=True)
assert call is not None
self.msg.note_call(supertype, call, context, code=code)
return False
Expand Down Expand Up @@ -4068,7 +4068,7 @@ def iterable_item_type(self, instance: Instance) -> Type:
# in case there is no explicit base class.
return item_type
# Try also structural typing.
iter_type = get_proper_type(find_member('__iter__', instance, instance))
iter_type = get_proper_type(find_member('__iter__', instance, instance, is_operator=True))
if iter_type and isinstance(iter_type, CallableType):
ret_type = get_proper_type(iter_type.ret_type)
if isinstance(ret_type, Instance):
Expand Down
4 changes: 2 additions & 2 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
if not any(mypy.sametypes.is_same_type(template, t)
for t in template.type.inferring):
template.type.inferring.append(template)
call = mypy.subtypes.find_member('__call__', template, actual)
call = mypy.subtypes.find_member('__call__', template, actual, is_operator=True)
assert call is not None
if mypy.subtypes.is_subtype(actual, erase_typevars(call)):
subres = infer_constraints(call, actual, self.direction)
Expand Down Expand Up @@ -430,7 +430,7 @@ def visit_callable_type(self, template: CallableType) -> List[Constraint]:
elif isinstance(self.actual, Instance):
# Instances with __call__ method defined are considered structural
# subtypes of Callable with a compatible signature.
call = mypy.subtypes.find_member('__call__', self.actual, self.actual)
call = mypy.subtypes.find_member('__call__', self.actual, self.actual, is_operator=True)
if call:
return infer_constraints(template, call, self.direction)
else:
Expand Down
2 changes: 1 addition & 1 deletion mypy/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,5 @@ def join_type_list(types: List[Type]) -> Type:
def unpack_callback_protocol(t: Instance) -> Optional[Type]:
assert t.type.is_protocol
if t.type.protocol_members == ['__call__']:
return find_member('__call__', t, t)
return find_member('__call__', t, t, is_operator=True)
return None
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ def incompatible_argument_note(self,
self.report_protocol_problems(original_caller_type, callee_type, context, code=code)
if (isinstance(callee_type, CallableType) and
isinstance(original_caller_type, Instance)):
call = find_member('__call__', original_caller_type, original_caller_type)
call = find_member('__call__', original_caller_type, original_caller_type,
is_operator=True)
if call:
self.note_call(original_caller_type, call, context, code=code)

Expand Down
2 changes: 1 addition & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def visit_overloaded(self, left: Overloaded) -> bool:
if isinstance(right, Instance):
if right.type.is_protocol and right.type.protocol_members == ['__call__']:
# same as for CallableType
call = find_member('__call__', right, left)
call = find_member('__call__', right, left, is_operator=True)
assert call is not None
if self._is_subtype(left, call):
return True
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy