-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working
Description
After reading https://discuss.python.org/t/when-should-we-assume-callable-types-are-method-descriptors/92938/9, I was curious to see if I could write structural method type, dual to the nominal ones in the types stdlib. But I ran into a bit of an issue:
from typing import Protocol
class HasSelf(Protocol):
@property
def __self__(self, /) -> object: ...
class A:
def f(self) -> None: ...
reveal_type(A.f.__self__) # ✅ type[A]
reveal_type(A().f.__self__) # ✅ A
f1: HasSelf = A.f # ❌ reportAssignmentType
f2: HasSelf = A().f # ❌ reportAssignmentType-
Type of "A.f.__self__" is "type[A]" -
Type of "A().f.__self__" is "A" -
Type "(self: A) -> None" is not assignable to declared type "HasSelf" "FunctionType" is incompatible with protocol "HasSelf" "__self__" is not present (reportAssignmentType) -
Type "() -> None" is not assignable to declared type "HasSelf" "FunctionType" is incompatible with protocol "HasSelf" "__self__" is not present (reportAssignmentType)
And I'm guessing that "__self__" is not present is not meant in a spiritual-philosophical sense :)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working