Closed bellini666 closed 1 year ago
This is great, thank you!!
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.
@bellini666 how about custom managers in app code?
Now we should use objects: MyCustomManager = MyCustomManager()
for correct typing?
@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
@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()
.
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: