-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Feature Request: Support django-polymorphic models in ManyToMany field #1836
Comments
Looks unrelated, but we have another issue with |
Since e.g. from django.db import models
from typing import TYPE_CHECKING
if TYPE_CHECKING:
PolymorphicModel = models.Model
else:
from xyz import PolymorphicModel
class Article(PolymorphicModel):
... This wouldn't start showing any declarations from |
This might be off topic, but I keep wondering if it's possible to use But I haven't gotten around to try it out myself. What I'm thinking about is doing: from django.db import models
from typing_extensions import Annotated
from xyz import PolymorphicModel as _PolymorphicModel
PolymorphicModel = Annotated[models.Model, _PolymorphicModel]
class Article(PolymorphicModel):
... |
Anyway I think the "proper" solution would be to get type stubs for |
Yes, getting typing for
|
I'm going to close this off with the reasoning that this is an issue for |
Thanks for looking into this and suggesting workarounds! |
Feature request
Sorry for filing this as a bug, i saw no other place to create a feature request.
And I thought posting here would make it easy for people with the same issue to find the reason.
What's wrong
When running mypy after upgrading to
django-stubs[compatible-mypy]==4.2.6
, i geterror: Need type annotation for "articles"
.Here, articles is defined as follows:
This is not due to the class being a string name as was the case in #1802.
We get four of these errors, and they are all for ManyToMany fields to the Article model.
The Article model is a polymorphic (https://github.com/django-polymorphic/django-polymorphic/) model:
This almost certainly is the reason for the error message. All other ManyToManyFields don't give this error.
How it should be
It would be nice if django-stubs could also support polymorphic models.
I realize that django-polymorphic has seen no activity in the last two years, and supporting it is not a priority. Also, I have no involvement with that project, we just use it (i wish we hadn't).
System information
python
version: 3.11.6django
version: 4.2.7mypy
version: 1.6.1django-stubs
version: 4.2.6django-stubs-ext
version: 4.2.5The text was updated successfully, but these errors were encountered: