Allow new-style self-types in classmethods#17381
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Member
Author
|
Hm, interestingly the last commit also fixed the primer somehow. Although this may seem good, it is actually suspicious, it may be that we handle access to self-type on unions incorrectly. Let me check this. |
Member
Author
|
Oh, yup, we incorrectly use |
Contributor
|
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:254: error: No overload variant of "__get__" of "AxisProperty" matches argument types "GroupBy[Any]", "type[GroupBy[Any]]" [call-overload]
- pandas/core/apply.py:254: note: Error code "call-overload" not covered by "type: ignore" comment
- pandas/core/apply.py:254: note: Possible overload variants:
- pandas/core/apply.py:254: note: def __get__(self, obj: DataFrame | Series, type: Any) -> Index
- pandas/core/apply.py:254: note: def __get__(self, obj: None, type: Any) -> AxisProperty
- pandas/core/apply.py:254: error: No overload variant of "__get__" of "AxisProperty" matches argument types "SeriesGroupBy", "type[SeriesGroupBy]" [call-overload]
- pandas/core/apply.py:254: error: No overload variant of "__get__" of "AxisProperty" matches argument types "DataFrameGroupBy", "type[DataFrameGroupBy]" [call-overload]
- pandas/core/apply.py:254: error: No overload variant of "__get__" of "AxisProperty" matches argument types "BaseWindow", "type[BaseWindow]" [call-overload]
- pandas/core/apply.py:254: error: No overload variant of "__get__" of "AxisProperty" matches argument types "Resampler", "type[Resampler]" [call-overload]
|
Member
Author
In fairness it looks like this time I contributed to both issues, LOL. In any case I am now happy with |
JukkaL
approved these changes
Jun 16, 2024
JukkaL
left a comment
Collaborator
There was a problem hiding this comment.
Nice to see some many bugs fixed!
asottile
added a commit
to asottile/django-stubs
that referenced
this pull request
Jul 25, 2024
there's a lot going on in the test but this specifically breaks lookup through `TypeVar` in mypy 1.11 (mypy 1.10 also failed in this way as well -- but was fixed in python/mypy#17381) test originally failing with: ``` /tmp/django-stubs/tests/typecheck/models/test_inheritance.yml:114: E pytest_mypy_plugins.utils.TypecheckAssertionError: Invalid output: E Actual: E myapp/models:23: error: Incompatible return value type (got "Bound", expected "T") [return-value] (diff) E Expected: E (empty) ```
sobolevn
pushed a commit
to typeddjango/django-stubs
that referenced
this pull request
Jul 25, 2024
there's a lot going on in the test but this specifically breaks lookup through `TypeVar` in mypy 1.11 (mypy 1.10 also failed in this way as well -- but was fixed in python/mypy#17381) test originally failing with: ``` /tmp/django-stubs/tests/typecheck/models/test_inheritance.yml:114: E pytest_mypy_plugins.utils.TypecheckAssertionError: Invalid output: E Actual: E myapp/models:23: error: Incompatible return value type (got "Bound", expected "T") [return-value] (diff) E Expected: E (empty) ```
asottile-sentry
added a commit
to getsentry/sentry
that referenced
this pull request
Jul 31, 2024
<!-- Describe your PR here. --> this had three sets of breakage addressed by other PRs: - our foreign key subclass was not functioning, django-stubs added a default TypeVar here which started getting filled in with an unbound TypeVar resulting in thousands of errors: fixed by #75228 - we were able to remove our fork's [descriptor patch](getsentry/sentry-forked-django-stubs#4) (which removed the non-model overload of `__get__` for fields) as mypy [fixed this issue](python/mypy#17381). in doing so it pointed out an unsafe descriptor access through a mixin and so that had to go: #75360 - django-stubs improved some field validation through QuerySets which was only checked through managers before: fixed by #75359
tamir-frenkel
pushed a commit
to tamir-frenkel/sentry
that referenced
this pull request
Nov 30, 2025
<!-- Describe your PR here. --> this had three sets of breakage addressed by other PRs: - our foreign key subclass was not functioning, django-stubs added a default TypeVar here which started getting filled in with an unbound TypeVar resulting in thousands of errors: fixed by getsentry#75228 - we were able to remove our fork's [descriptor patch](getsentry/sentry-forked-django-stubs#4) (which removed the non-model overload of `__get__` for fields) as mypy [fixed this issue](python/mypy#17381). in doing so it pointed out an unsafe descriptor access through a mixin and so that had to go: getsentry#75360 - django-stubs improved some field validation through QuerySets which was only checked through managers before: fixed by getsentry#75359
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16547
Fixes #16410
Fixes #5570
From the upvotes on the issue it looks like an important use case. From what I see this is an omission in the original implementation, I don't see any additional unsafety (except for the same that exists for instance methods/variables). I also incorporate a small refactoring and remove couple unused
get_proper_type()calls.The fix uncovered an unrelated issue with unions in descriptors, so I fix that one as well.