Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Pavel Noryk
    @PNoryk
    BLANK_NULL: dict[str, bool] = {"blank": True, "null": True}
    birthday = models.DateField("Дата рождения", **consts.BLANK_NULL)
    Argument 2 to "DateField" has incompatible type "**Dict[str, bool]"
    Alex Oleshkevich
    @alex-oleshkevich

    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!

    Eugene Korostylov
    @mcxemic

    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?

    James Stewart Miller
    @millerthegorilla
    This message was deleted
    James Stewart Miller
    @millerthegorilla

    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'?

    1 reply
    Jamie Coombes
    @jcoombes

    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#

    2 replies
    Primož Erjavec
    @primoze
    Hi all. I have a question about the version compatibility matrix on https://pypi.org/project/django-stubs/, specifically can I use mypy 0.910 with django-stubs 1.7.0 (for django 3.0.5), because I want to ignore all 'test_*' files, and mypy 0.790 doesn't yet have the exclude option.
    michaelanckaert
    @michaelanckaert:matrix.org
    [m]
    Hello everyone. I'm trying to debug an issue with the django-stubs where I get mypy errors about "ModelName has no attribute 'id'". I have the django plugin configured in the mypy configuration but this still creeps up as a mypy error.
    I tried searching for solutions but didn't come up with anything.
    I have also noticed that related fields are not picked up as valid attributes. This makes me think there is an issue with the way the plugin is detected or configured.
    Dušan Maliarik
    @skrat
    ImportError: cannot import name 'RelatedManager' from 'django.db.models.manager' why this?
    I am declaring the attribute in my related model, ie. I have class Product... colors: RelatedManager['Color'] ... class Color... product = ForeignKey(..., related_name='colors')
    2 replies
    Jacek Bronski-Jankowski
    @jacekbj

    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

    Jacek Bronski-Jankowski
    @jacekbj
    Winter holiday break is really long this year! I wish you all the best and hope to hear from you soon!
    François GUÉRIN
    @frague59
    Hi
    Is it a way to provide the source root directory in the [tool.django-stubs] directive in a pyproject.toml file ?
    My main module is not in the root of the directory, but in a src folder
    I've for now:
    [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
    I've an error on pre-commit: `ModuleNotFoundError: No module named 'seniors'```
    François GUÉRIN
    @frague59
    If I set django_settings_module = "src.seniors.settings.dev", it works for the main entry but breaks after, trying to import 'account' which has become 'src.account' - this is not my working tree...
    ... I don't want to change my tree !
    François GUÉRIN
    @frague59
    Any ideas ?
    Corey Rice
    @coreyar
    have you tried setting the mypy_path to src
    Aleksander Vognild Burkow
    @aleksanb
    There seems to be a crash with mypy 931 and the newest master of mypy-django
    hm i might know why
    Hehe, i think it's a custom patch i had that might not be needed anymore that caused the crash
    Aleksander Vognild Burkow
    @aleksanb
    jep!
    wow, django-stubs has gotten a lot better over the last month
    amazing work
    Aleksander Vognild Burkow
    @aleksanb
    say, could we get a new pypi-release?
    Aleksander Vognild Burkow
    @aleksanb
    bilde.png
    is this the model that needs a new field?
    I can't find any references to do_not_cache, but if we're supposed to set no_serialize on our Annotated class, does that even make sense? Wouldn't it have to subclass SymbolTableNode or something
    Parth Shingari
    @parthshingari28

    error: Need type annotation for "city"

    I am getting alot of errors while integrating mypy with my codebase ...... can anyone pls help me out to resolve it ???

    1 reply
    Parth Shingari
    @parthshingari28
    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 ???
    Aleksander Vognild Burkow
    @aleksanb
    Is it possible to sponsor the development of django-mypy somehow? I see there's an opencollective, but unsure whether it's in use and no clear doc where the money would go.
    Ivan Timoshenko
    @chudomozg

    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

    • repo: https://github.com/pre-commit/mirrors-mypy
      rev: ''
      hooks:
      • id: mypy
        exclude: "[a-zA-Z]/(migrations)/(.)"
        args: [--config=setup.cfg,
           --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

    Himanshu Balasamanta
    @Himanshu-Balasamanta
    Till which version of Django are there stubs for all methods and classes?
    Leo Trubach
    @leotrubach
    Hi all. How do I annotate any model type? Planning to use that when doing some generic signals
    Peter Kools
    @peterkools
    Hi folks. Thanks to the contributors for the django-stubs package - it's been very helpful! I do have one question. I am using django-stubs 1.10 package with mypy 0.942. Using the @staff_member_required decorator, I get the error 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.
    horpto
    @horpto

    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

    henribru
    @henribru
    It seems that if you use a custom query set, after you call .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?
    henribru
    @henribru
    Though this issue might not be solvable without support for higher-kinded types ...
    Unless the plugin can do something smart I guess
    Ioannis Latousakis
    @latusaki
    Hey guys, bumped some versions today, and got a quite long list of mypy errors. django-stubs from 1.9.0 to 1.10.1 and django-stubs-ext from 0.3.1 to 0.4.0. Some things like attr-defined for 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
    Ioannis Latousakis
    @latusaki
    Looks like this may be at least partially related: typeddjango/django-stubs#902