-
-
Notifications
You must be signed in to change notification settings - Fork 453
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
Make Model.objects a ClassVar #394
Conversation
The test suite is failing, but master is also failing on Travis, so I'm not sure if that's my fault. I also don't really understand why this one line change would cause so many test failures. |
@davidhalter that's totally not your fault. We have some unexpected failures from our build system. |
@@ -22,7 +22,7 @@ class Model(metaclass=ModelBase): | |||
class Meta: ... | |||
_meta: Options[Any] | |||
_default_manager: BaseManager[Model] | |||
objects: BaseManager[Any] | |||
objects: ClassVar[BaseManager[Any]] |
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.
This is a great addition! But, this does raise an important topic to discuss.
Currently, we do not treat properties as ClassVar
s. I guess that we need to fix that. And mark ones that apply as ClassVar
s.
@danifus can you please open a new issue?
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.
Hi, was this comment intended for me or @davidhalter?
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.
Oups! 😆 My bad!
But, feel free to participate!
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.
@sobolevn I don't really understand what needs to be fixed. I see that the CI is still failing even after I force pushed an amended commit. I'm guessing that has something to do with the Mypy plugin. But since I'm not using Mypy, I'm only interested in correct type annotations and I would appreciate if you guys could take it from here.
I obviously understand that this is more work, but it's not my forte. As a temporary measure, I might just ship a patched version in Jedi until this gets fixed.
Still thanks for looking at it @sobolevn!
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.
@sobolevn Failing tests are not a matter of the bug I've fixed, I've just checked that. Introducing ClassVars to our stubs it quite a big change. It'd be awesome @davidhalter if you could create an issue on this one. As @sobolevn wrote, marking properties that apply as ClassVar
would be a lot of help too. Thank you for your work, I can take it from here if you want me to 😄
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.
@kszmigiel Yeah feel free to take it from here, I really have no idea :)
I can of course create an issue, but I'd rather not, since I really don't understand what the issue is. The issue would probably have the content "ClassVar for Model.objects
doesn't work". If that has value for you, I'm fine doing that :).
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.
@davidhalter Sure thing, I'll create an issue for that later, thanks for pointing this out 😄
Thanks a lot for your work! 👍 |
The CI is fixed. |
This includes the fix in typeddjango/django-stubs#394
Model.objects is only available on classes and while we cannot force this, without ClassVar it's kind of only available on instances. I have noticed this when I was writing a Jedi plugin that makes django-stubs work properly.
I’ve rebase this PR - @sobolevn want to double check and merge? |
Looks like this needs a bit more work:
|
Yeah I was just looking at this. We can add It might also annoying to users if they have to add |
This is what we do in typeshed at least. |
So you think we can close this one? It does seem quite disruptive. |
Yes, I think so. @davidhalter thank you for your proposal! If anyone wants to submit a full-featured solution, please provide real-world use-cases where this can be useful first. |
Cross linking: it looks like #1150 may have resolved this. |
I feel like I also changed the default behavior of non-ClassVar variables on classes to be available on classes as well. This is something that Mypy allows as well, so I figured we are probably not wrong to allow that. |
Model.objects is only available on classes and while we cannot force this, without ClassVar it's kind of only available on instances.
I have noticed this when I was writing a Jedi plugin that makes django-stubs work properly.