-
Notifications
You must be signed in to change notification settings - Fork 13
test: verify correct typing of mixins #280
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the pull request, @bradenmacdonald! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
# interface as the base manager class. | ||
objects: models.Manager[Component] = WithRelationsManager( | ||
# Set up our custom manager. It has the same API as the default one, but selects related objects by default. | ||
objects: ClassVar[WithRelationsManager[Component]] = WithRelationsManager( # type: ignore[assignment] |
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.
Unfortunately this line still requires specifying the type explicitly and also needs ignore[assignment]
because mypy for some reason thinks that WithRelationsManager[Component]
and WithRelationsManager[Self]
are different things in this case. Seems like a mypy bug 🤷🏻♂️.
In all other cases, where we're just using WithRelationsManager
directly or just relying on a mixin to provide objects, no type annotations or suppression are needed. It's just here where the override in Component
seems to conflict with the override in PublishableEntityMixin
(though it shouldn't).
47a5503
to
ae8ac62
Compare
ae8ac62
to
96679ff
Compare
|
||
objects: models.Manager[PublishableEntityMixin] = PublishableEntityMixinManager() | ||
# select these related entities by default for all queries | ||
objects: ClassVar[WithRelationsManager[Self]] = WithRelationsManager( |
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.
It's actually possible to remove this ClassVar[WithRelationsManager[Self]]
annotation, and everything will still be correct. Though it seems VS Code / Pyright then interprets it as Manager[Self]
rather than WithRelationsManager[Self]
, whereas mypy is unaffected. I don't have a strong opinion but it seems fine to be more explicit.
Friendly ping on this, @ormsbee :) |
96679ff
to
9735024
Compare
This was mostly included in #278 . Now the only new thing here are some tests to verify that the typing is correct. |
7f8afba
to
a56fbc5
Compare
a56fbc5
to
fa0424d
Compare
This PR makes some simplifications to
PublishableEntityMixin
andPublishableEntityVersionMixin
so that their subclasses likeComponentVersion
automatically get the correct type on theirobjects
class property, and don't have to override it to satisfy mypy. This will slightly simplify the code as we get more publishable entities in the near future (e.g. components and units).I also got rid of the custom
PublishableEntityMixinManager
andPublishableEntityVersionMixinManager
classes, replacing them with the reusableWithRelationsManager
that does the same thing and which now supports generic typing properly.New type-only tests are added to assert that the typing of the manager (
objects
) and its returned instances are correct.