-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Update property.fget
, property.fset
, and property.fdel
#7520
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
Conversation
This comment has been minimized.
This comment has been minimized.
On seeing that primer diff, maybe typeshed is right and this is a pyright issue? |
Mypy and pyright disagree here. Here's a minimal example: from typing import Callable
class X:
f: Callable[[], int]
g: Callable[["X"], int]
reveal_type(X().f())
reveal_type(X().g()) Pyright complains about the second call ( I feel like pyright is right here, because the behavior where In either case, the discrepancy is unfortunate because it means we can't write typeshed stubs that satisfy both type checkers. Perhaps we should raise a discussion at the github.com/python/typing repo, come to a consensus, and update one type checker or the other. |
I find mypy's behavior weird, because not all callables are descriptors. In #4484, I used this workaround for it:
I believe this works consistently in mypy and pyright, but I haven't checked. |
So @Akuli's workaround seems to fix @JelleZijlstra's minimal example. However, if I try and make the same changes to For the code in the linked issue: class A:
@property
def foo(self):
return 'a'
A.foo.fget(A()) mypy: Seems like mypy can't infer that Will make an issue in the typing repo for discussion and close this PR for now |
Let's see what mypy_primer says about this now that mypy 0.981 is released. |
Diff from mypy_primer, showing the effect of this PR on open source code: spark (https://github.com/apache/spark)
+ python/pyspark/pandas/frame.py:13489: error: Too few arguments [call-arg]
+ python/pyspark/pandas/frame.py:13489: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/frame.py:13489: error: Argument 1 has incompatible type "DataFrame[T]"; expected "property" [arg-type]
+ python/pyspark/pandas/series.py:7264: error: Too few arguments [call-arg]
+ python/pyspark/pandas/series.py:7264: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/series.py:7264: error: Argument 1 has incompatible type "Series[T]"; expected "property" [arg-type]
+ python/pyspark/pandas/groupby.py:3738: error: Too few arguments [call-arg]
+ python/pyspark/pandas/groupby.py:3738: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/groupby.py:3738: error: Argument 1 has incompatible type "DataFrameGroupBy"; expected "property" [arg-type]
+ python/pyspark/pandas/groupby.py:3923: error: Too few arguments [call-arg]
+ python/pyspark/pandas/groupby.py:3923: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/groupby.py:3923: error: Argument 1 has incompatible type "SeriesGroupBy"; expected "property" [arg-type]
+ python/pyspark/pandas/indexes/base.py:2672: error: Too few arguments [call-arg]
+ python/pyspark/pandas/indexes/base.py:2672: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/indexes/base.py:2672: error: Argument 1 has incompatible type "Index"; expected "property" [arg-type]
+ python/pyspark/pandas/indexes/timedelta.py:128: error: Too few arguments [call-arg]
+ python/pyspark/pandas/indexes/timedelta.py:128: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/indexes/timedelta.py:128: error: Argument 1 has incompatible type "TimedeltaIndex"; expected "property" [arg-type]
+ python/pyspark/pandas/indexes/multi.py:997: error: Too few arguments [call-arg]
+ python/pyspark/pandas/indexes/multi.py:997: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/indexes/multi.py:997: error: Argument 1 has incompatible type "MultiIndex"; expected "property" [arg-type]
+ python/pyspark/pandas/indexes/datetimes.py:141: error: Too few arguments [call-arg]
+ python/pyspark/pandas/indexes/datetimes.py:141: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/indexes/datetimes.py:141: error: Argument 1 has incompatible type "DatetimeIndex"; expected "property" [arg-type]
+ python/pyspark/pandas/window.py:205: error: Too few arguments [call-arg]
+ python/pyspark/pandas/window.py:205: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/window.py:205: error: Argument 1 has incompatible type "Rolling[FrameLike]"; expected "property" [arg-type]
+ python/pyspark/pandas/window.py:900: error: Too few arguments [call-arg]
+ python/pyspark/pandas/window.py:900: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/window.py:900: error: Argument 1 has incompatible type "RollingGroupby[FrameLike]"; expected "property" [arg-type]
+ python/pyspark/pandas/window.py:1438: error: Too few arguments [call-arg]
+ python/pyspark/pandas/window.py:1438: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/window.py:1438: error: Argument 1 has incompatible type "Expanding[FrameLike]"; expected "property" [arg-type]
+ python/pyspark/pandas/window.py:1948: error: Too few arguments [call-arg]
+ python/pyspark/pandas/window.py:1948: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/window.py:1948: error: Argument 1 has incompatible type "ExpandingGroupby[FrameLike]"; expected "property" [arg-type]
+ python/pyspark/pandas/window.py:2492: error: Too few arguments [call-arg]
+ python/pyspark/pandas/window.py:2492: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/window.py:2492: error: Argument 1 has incompatible type "ExponentialMoving[FrameLike]"; expected "property" [arg-type]
+ python/pyspark/pandas/window.py:2593: error: Too few arguments [call-arg]
+ python/pyspark/pandas/window.py:2593: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/window.py:2593: error: Argument 1 has incompatible type "ExponentialMovingGroupby[FrameLike]"; expected "property" [arg-type]
+ python/pyspark/pandas/resample.py:714: error: Too few arguments [call-arg]
+ python/pyspark/pandas/resample.py:714: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/resample.py:714: error: Argument 1 has incompatible type "DataFrameResampler"; expected "property" [arg-type]
+ python/pyspark/pandas/resample.py:746: error: Too few arguments [call-arg]
+ python/pyspark/pandas/resample.py:746: note: "fget" is considered instance variable, to make it class variable use ClassVar[...]
+ python/pyspark/pandas/resample.py:746: error: Argument 1 has incompatible type "SeriesResampler"; expected "property" [arg-type]
|
Hmm, that still looks pretty bad. And, looking at this issue again, I think we might have misdiagnosed a little bit here. Following the release of mypy 0.981, mypy and pyright now agree on the snippet @JelleZijlstra posted in #7520 (comment): https://mypy-play.net/?mypy=latest&python=3.10&gist=276f0399f36c37f6e291f43b277cec65. And looking at the stubs again, I think maybe typeshed is correct at the moment. Maybe this is just an issue with pyright's special-casing here. |
And indeed, I can no longer reproduce the error in #7516 using VSCode. So, it seems like this was a pyright problem, and that it's now fixed 🥳 |
Closes #7516.
These property methods take
property
type as first arg and then the desired instance.