birthday = models.DateField("Дата рождения", **consts.BLANK_NULL)
hello everyone!
what is the proper way to typehint custom filter backends in DRF?
The snippet below gives me that error:error: Return type "QuerySet[Organization]" of "filter_queryset" incompatible with return type "_Q" in supertype "BaseFilterBackend"
class Organization(models.Model): ...
class ByCurrentOrganization(BaseFilterBackend):
def filter_queryset(self, request: Request, queryset: QuerySet[Organization], view: APIView) -> QuerySet[Organization]:
return queryset.filter(organization=request.organization)
thanks in advance!
Hi folks! Does anyone know how to properly type custom methods for the User class in Django? I've added a method to using add_to_class
method in models.py:
def url(self):
return 'some-url'
User.add_to_class('url', url)
But when I`m trying to get this method in code I get:error: "User" has no attribute "url" [attr-defined]
Should I redeclare User
somewhere or maybe you know other solutions?
Hi, I use a signal to create a Profile Model, with a one-to-one field to the User model. When a User model is created, the signal fires and creates a Profile model with a field profile_user that points at the User class, and has a relatedname of 'profile'. I can then address the profile by using 'some_user.profile'.
Mypy complains :
"User" has no attribute "profile"
Is there a way to either silence this error (without silencing all attr-defined errors, or alternatively, and better imo, some way of custom specifying a type for the User class that includes the attribute 'profile'?
Hi all, I'm typing my admin.py and I was successfully able to use this answer to add type parameters to ModelAdmin - https://stackoverflow.com/a/67977204/13582009
I'm having the same error for my StackedInline too.Missing type parameters for generic type "StackedInline" [type-arg]
class AttendanceInline(StackedInline):
"""Inline used to specify attendances at the same time as setting up a session."""
model = Attendance
extra = 1
Would the solution here be to add StackedInline to the _needs_generic
list in the django monkeypatch function defined in the PR here?
https://github.com/typeddjango/django-stubs/pull/526/files#
class Product... colors: RelatedManager['Color'] ... class Color... product = ForeignKey(..., related_name='colors')
Hi!
I have a very basic example but couldn't scroll to anything similar in this Gitter room.
from django.db import models
class Poll(models.Model):
name = models.CharField(max_length=10)
from polls.models import Poll
def foo() -> int:
return Poll.objects.first()
When running mypy on the second snippet, it fails with: polls/views.py:8: error: Incompatible return value type (got "Optional[Any]", expected "int")
I'm wondering why it's Optional[Any]
and not Optional[Poll]
. I've got those packages installed (that's a project built entirely for the purpose of checking this issue):
asgiref==3.4.1
Django==3.2.10
django-stubs==1.9.0
django-stubs-ext==0.3.1
mypy==0.930
mypy-extensions==0.4.3
pytz==2021.3
sqlparse==0.4.2
toml==0.10.2
tomli==2.0.0
typed-ast==1.5.1
types-pytz==2021.3.3
types-PyYAML==6.0.1
typing-extensions==4.0.1
Python 3.7
[tool.django-stubs]
directive in a pyproject.toml file ?
[tool.django-stubs]
django_version = "3.2"
django_apps = ["account", "seniors", "seniors_app"]
django_settings_module = "seniors.settings.dev"
ignore_missing_settings = true
ignore_missing_model_attributes = true
mypy.ini:6: error: Error importing plugin "mypy_django_plugin.main
mypy_drf_plugin.main": No module named 'mypy_django_plugin.main\nmypy_drf_plugin'
Found 1 error in 1 file (errors prevented further checking)
Anyone pls help .... I'm getting this error again and again ???
Hi, guys. I've tried to configurate pre-commit + mypy + django stubs like in documentation. But i have error
ModuleNotFoundError: No module named 'environ'
It's look like mypy doesn't use option ignore_missing_imports = True ????
My files
.pre-commit-config.yaml
--no-strict-optional,
--ignore-missing-imports]
additional_dependencies: [django-stubs]setup.cfg
[mypy]
allow_redefinition = True
check_untyped_defs = True
ignore_missing_imports = True
incremental = True
strict_optional = True
show_traceback = True
warn_no_return = False
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
plugins = mypy_django_plugin.main
show_column_numbers = True
[mypy.plugins.django-stubs]
django_settings_module = config.settings.local
[mypy_django_plugin]
ignore_missing_model_attributes = True
Untyped decorator makes function "XXX" untyped
, followed by <nothing> not callable
. I haven't found anything on stackoverflow or Google about how to resolve this and was wondering if anyone in this group has a suggestion. I had the same errors with django-stubs 1.9 and mypy 0.931.
Hi folks, i have trouble with new version and class property. webpay/models.py:30: error: Argument 1 to "classproperty" has incompatible type "Callable[[WebPayStatus], Any]"; expected "Optional[Callable[[Type[<nothing>]], <nothing>]]"
class property is quite simple:
from django.utils.functional import classproperty
class WebPayStatus(Choice):
@classproperty
def success(self):
return self.COMPLETED, self.AUTHORIZED, self.RECURRENT
Is it bug or I need to specify some typings? mypy=0.942, python==3.10, django==3.2, django-stubs==1.10.1
.values(...)
you're no longer allowed to call methods from your custom query set because the type is just inferred as _QuerySet. I didn't find an existing issue about this on Github and didn't, but possibly I'm just bad at searching, so before I open one, does anyone knows if one exists?
django.db.models.Model.{related_name}
fields. Trying to find anything that would explain why this is happening, any obvious change that could cause this? python 3.10.1 Django 3.2.13