-
-
Notifications
You must be signed in to change notification settings - Fork 521
Closed
Labels
bugSomething isn't workingSomething isn't workingmypy-pluginIssues specific to mypy_django_pluginIssues specific to mypy_django_plugin
Description
What's wrong
I have the following model:
class Customer(User):
addresses = models.ManyToManyField(
Address,
related_name="customers",
null=True,
blank=True,
)
addresses here is typed as RelatedManager[<model>] | None. meaning any queryset call on it will make mypy complain about the attribute not existing. For example:
project/views/address.py:68: error: Item "None" of "RelatedManager[Address] | None" has no attribute "add" [union-attr]
project/views/address.py:93: error: Item "None" of "RelatedManager[Address] | None" has no attribute "get" [union-attr]
project/views/address.py:97: error: Item "None" of "RelatedManager[Address] | None" has no attribute "remove" [union-attr]
However, it never is None, and I'm not sure how it could be either. If there are no addresses for a customer than customer.addresses.exists() would just return false rather than customer.addresses being None.
How is that should be
It should be typed as just RelatedManager[<model>].
System information
- OS: Linux
pythonversion: 3.11djangoversion: 4.2mypyversion: 1.4.1django-stubsversion: 4.2.3django-stubs-extversion: not installed
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmypy-pluginIssues specific to mypy_django_pluginIssues specific to mypy_django_plugin