-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
TYP: cache_readonly #43252
TYP: cache_readonly #43252
Conversation
pandas/_libs/properties.pyi
Outdated
|
||
class cache_readonly(Protocol[_F, _G]): | ||
def __init__(self, func: Callable[[_F], _G]) -> None: ... | ||
def __get__(self, obj: _F, typ) -> _G: ... |
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 don't know what the variable typ
is.
The return value of __get__
can also be self
(is that intended?):
pandas/pandas/_libs/properties.pyx
Line 23 in b9e90dc
return self |
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.
The return value of get can also be self (is that intended?):
Yes, this happens when you lookup cls.foo on the class rather than on an instance
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.
Thanks, I added an overload for this.
The current type stubs do not handle this case
pandas/pandas/_libs/properties.pyx
Line 30 in b9e90dc
except (AttributeError): |
If the only solution to cover this case is to return
_G | cache_readonly[_F, _G]
, I am inclined to not cover this case as it would make the annotations less useful (even though it would be correct): index.right
would then be a union of two types.
If the CI failures prove hard to resolve, could we cheat and write in the .pyi something like |
I must admit, I didn't notice the many mypy failures. I will put the PR into draft mode and locally debug it until I get it working. I will ping you when it is ready :) |
I mistakenly used Some remaining |
see #41588 (comment) |
I'm not sure how to test this on the CI - pyright is happy on my machine: