Skip to content

fix: fix objects attribute for pyright 1.1.324 #181

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

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

bellini666
Copy link

The way CPython works at runtime is to give a higher priority to the metaclass descriptors than the ones in the class itself.

Pyright 1.1.324 adjusted that but made our .objects typing break when using our own custom managers.

Nowadays we can use Self for that, which not only is more elegant but also solves this issue in a way that both mypy and pyright can resolve correctly.

Related issues:

The way CPython works at runtime is to give a higher priority to
the metaclass descriptors than the ones in the class itself.

Pyright 1.1.324 adjusted that but made our `.objects` typing break
when using our own custom managers.

Nowadays we can use `Self` for typing, which not only is more elgant
but also solves this issue in a way that both mypy and pyright
can resolve correctly.
@kodiakhq kodiakhq bot merged commit c862c7f into sbdchd:main Aug 25, 2023
@sbdchd
Copy link
Owner

sbdchd commented Aug 25, 2023

This is great, thank you!!

@bellini666
Copy link
Author

Thank you @sbdchd ! :)

Just to let you know, this solution has a small issue on pyright 1.1.324 which will get resolved on 1.1.325. As soon as that version is released (probably in the next few days, based on pyright's release cadence) django-types can release a new version as well.

@last-partizan
Copy link

@bellini666 how about custom managers in app code?

Now we should use objects: MyCustomManager = MyCustomManager() for correct typing?

@bellini666
Copy link
Author

@bellini666 how about custom managers in app code?

Now we should use objects: MyCustomManager = MyCustomManager() for correct typing?

If you have a custom manager, indeed! That's what I do

@JakobGM
Copy link

JakobGM commented Oct 13, 2023

@bellini666 how about custom managers in app code?
Now we should use objects: MyCustomManager = MyCustomManager() for correct typing?

If you have a custom manager, indeed! That's what I do

I think, and correct me if I'm wrong, an even more correct type annotation would be objects: ClassVar[MyCustomManager]: MyCustomManager().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants