sbdchd / django-types

:doughnut: Type stubs for Django
MIT License
187 stars 62 forks source link

fix: fix objects attribute for pyright 1.1.324 #181

Closed bellini666 closed 1 year ago

bellini666 commented 1 year ago

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:

sbdchd commented 1 year ago

This is great, thank you!!

bellini666 commented 1 year ago

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 commented 11 months ago

@bellini666 how about custom managers in app code?

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

bellini666 commented 11 months ago

@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 commented 11 months ago

@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().