-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix: incorrect returned type of access descriptors on unions of types #16604
fix: incorrect returned type of access descriptors on unions of types #16604
Conversation
This comment has been minimized.
This comment has been minimized.
c2a55af
to
3ab43bc
Compare
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/apply.py:265: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/apply.py:265: error: No overload variant of "__get__" of "AxisProperty" matches argument types "GroupBy[Any]", "type[GroupBy[Any]]" [call-overload]
+ pandas/core/apply.py:265: note: Error code "call-overload" not covered by "type: ignore" comment
+ pandas/core/apply.py:265: note: Possible overload variants:
+ pandas/core/apply.py:265: note: def __get__(self, obj: DataFrame | Series, type: Any) -> Index
+ pandas/core/apply.py:265: note: def __get__(self, obj: None, type: Any) -> AxisProperty
+ pandas/core/apply.py:265: error: No overload variant of "__get__" of "AxisProperty" matches argument types "SeriesGroupBy", "type[SeriesGroupBy]" [call-overload]
+ pandas/core/apply.py:265: error: No overload variant of "__get__" of "AxisProperty" matches argument types "DataFrameGroupBy", "type[DataFrameGroupBy]" [call-overload]
+ pandas/core/apply.py:265: error: No overload variant of "__get__" of "AxisProperty" matches argument types "BaseWindow", "type[BaseWindow]" [call-overload]
+ pandas/core/apply.py:265: error: No overload variant of "__get__" of "AxisProperty" matches argument types "Resampler", "type[Resampler]" [call-overload]
|
@JukkaL could you or another maintainer take a look at this PR? It's (hopefully) a fairly simple fix to a fairly common sqlalchemy typing complaint. Thanks |
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 for the fix!
…#16604) Fixes #16603 This change maps over union types when determining the types of access descriptors. Previously, the because [this conditional](https://github.com/md384/mypy/blob/c2a55afcef32ecb11a4c76c4c79539f6ba36d55c/mypy/checkmember.py#L697-L701) would fall through to the `else` case because instance type was not a singular `TypeType` (it was a Union), so we'd end up with an instance value being passed to `__get__` instead of `None`.
This PR fixed and revealed a new error with typing django models w/django-stubs. Both Invoice and GroupInvoice here are django Models being pointed to from a third model, SalesDocument.
But the following code errors out:
After this patch, mypy is able to reveal the type of invoice.sales_document correctly as SalesDocument,
|
@aleksanb I suspect this is a django-stubs bug in the plugin code. Please file in that repo. |
Fixes #16603
This change maps over union types when determining the types of access descriptors. Previously, the because this conditional would fall through to the
else
case because instance type was not a singularTypeType
(it was a Union), so we'd end up with an instance value being passed to__get__
instead ofNone
.