Skip to content

Commit c3112fd

Browse files
authored
Try modenizing PR implementation
1 parent 2daff28 commit c3112fd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mypy/checkmember.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,17 @@ def analyze_var(
900900
and call_type.type.is_protocol
901901
and call_type.type.get_method("__call__")
902902
):
903-
call_type = get_proper_type(_analyze_member_access("__call__", typ, mx))
903+
# This is ugly, but it reflects the reality that Python treats
904+
# real functions and callable objects differently in class bodies.
905+
# We want to make callback protocols behave like the former.
906+
proto_mx = mx.copy_modified(original_type=typ, self_type=typ, is_lvalue=False)
907+
call_type = get_proper_type(_analyze_member_access("__call__", typ, proto_mx))
908+
if isinstance(call_type, CallableType):
909+
call_type = call_type.copy_modified(is_bound=False)
910+
elif isinstance(call_type, Overloaded)
911+
call_type = Overloaded(
912+
[it.copy_modified(is_bound=False) for it in call_type.items()]
913+
)
904914

905915
# Bound variables with callable types are treated like methods
906916
# (these are usually method aliases like __rmul__ = __mul__).

0 commit comments

Comments
 (0)