Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def expand_and_bind_callable(
) -> Type:
if not mx.preserve_type_var_ids:
functype = freshen_all_functions_type_vars(functype)
typ = get_proper_type(expand_self_type(var, functype, mx.original_type))
typ = get_proper_type(expand_self_type(var, functype, mx.self_type))
assert isinstance(typ, FunctionLike)
if is_trivial_self:
typ = bind_self_fast(typ, mx.self_type)
Expand Down
5 changes: 4 additions & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,10 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]:
# like U -> U, should be Callable[..., Any], but if U is a self-type, we can
# allow it to leak, to be later bound to self. A bunch of existing code
# depends on this old behaviour.
and not any(tv.id.is_self() for tv in cactual.variables)
and not (
any(tv.id.is_self() for tv in cactual.variables)
and template.is_ellipsis_args
)
):
# If the actual callable is generic, infer constraints in the opposite
# direction, and indicate to the solver there are extra type variables
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -4646,3 +4646,17 @@ reveal_type(t.bar) # N: Revealed type is "def () -> builtins.int"
tt: Type[P] = C
reveal_type(tt.foo) # N: Revealed type is "def (builtins.object) -> builtins.int"
reveal_type(tt.bar) # N: Revealed type is "def (builtins.object) -> builtins.int"

[case testProtocolDecoratedSelfBound]
from abc import abstractmethod
from typing import Protocol, Self

class Proto(Protocol):
@abstractmethod
def foo(self, x: Self) -> None: ...

class Impl:
def foo(self, x: Self) -> None:
pass

x: Proto = Impl()