by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Silvio
    @silviogutierrez
    but now, mypy rightly complains (because of LSP):
    class ObtainAuthTokenAndBringOverAnonymousProfiles(ObtainAuthToken):
        def post(self, request: stubs.Request, *args: Any, **kwargs: Any) -> Response:  # type: ignore[override]
    I have to ignore the override
    coiax
    @coiax
    Does anyone have any resources to point me to for annotating third party libraries providing fields?
    We're now using https://github.com/5monkeys/django-enumfield Django Enumfields in our project, but the get/set types of the field are coming out as Any/Any
    When it should really be int/TheEnumYou'reUsing
    Nikita Sobolev
    @sobolevn
    @coiax that's an awesome question. Can you please open a new issue for this?
    coiax
    @coiax
    Sure
    coiax
    @coiax
    hope that's what you were looking for
    David Grant
    @dgrant
    @coiax just in case you weren't aware there is some better support for enums in Django now: https://docs.djangoproject.com/en/3.0/ref/models/fields/#field-choices-enum-types
    coiax
    @coiax
    Yeah, sadly we're currently stuck on Django 2.2 because one of our other third party libraries is using deprecated functionality
    Also, I don't know if django-stubs has been released for Django 3.0 yet
    Lachlan Cannon
    @lcannon

    Hi, I've done a little googling but couldn't find anything relevant, apologies if I've overlooked.

    I'm looking to integrate mypy with django stubs into our mono-repo via sticklerci, and I don't know what I should be doing for the django_settings_module setting -- since it will be a different file depending on which project(s) it's running on.

    Is there a way to handle this, or should I be contacting stickler to ask for the ability to specify a different mypy.ini based on the repo path?
    Silvio
    @silviogutierrez
    @coiax : I think you can always type in manually
    like the days before Django-stubs was a thing
    my_field: ManualType = some_library.fields.CustomField()
    Anton Linevych
    @linevych

    Hi guys, is there any way to make this to work?

    class SomeManager(Manager.from_queryset(SomeQuerySet)):
        pass

    Right now mypy complains about Unsupported dynamic base class "Manager.from_queryset".

    Rory Byrne
    @synek

    Hi folks, quick question (I'm relatively new to typed Python):

    Why is the package named with a hyphen - rest_framework-stubs? I want to do something like the below:

    from rest_framework-stubs.response import Response
    resp: Response = c.get('/')

    The problem here is that rest_framework-stubs is an illegal import due to the hyphen.

    What's going on? Should I even be using the stubs in this way?

    Lachlan Cannon
    @lcannon
    I believe you should just be using DRF's own response class to type annotate
    from rest_framework.response import Response
    
    
    resp: Response = c.get('/')
    Rory Byrne
    @synek
    @lcannon You're right, thanks.
    Unrelated: I see in the django-stubs README that Manager[MyModel] should be quoted as 'Manager[MyModel]' to avoid a type error, but this is not possible when subclassing. For example, I want to create a subclass class MyUserManager(BaseUserManager[MyUser]), but this triggers a TypeError. I cannot put it in quotes since it's inside the class definition. Is there any workaround while we wait for pull request 12405?
    Again please let me know if I'm mis-using Python typing here
    Rory Byrne
    @synek
    The problem is caused by circular imports, since MyUser references MyManager, and MyManager references MyUser due to the necessity of including the [MyUser] typing in the MyManager definition
    I guess I'll just import it with django.apps. Or can I use a stub of MyUser to avoid importing MyUser?
    That doesn't work either because then I have an un-typed user: ??? = apps.get_model('auth', 'MyUser')
    Any ideas are welcome, apologies for the wall of text
    Rory Byrne
    @synek
    I was being silly again. The correct way to subclass BaseUserManager is along the lines of T = TypeVar('T'); class MyUserManager(BaseUserManager[T])
    Rory Byrne
    @synek
    ...And that's held up by PR 12405 - I'll wait for it to be merged
    Marti Raudsepp
    @intgr
    @RoryOfByrne You can use if TYPE_CHECKING as a work-around for the subclassing issue
    Or did you already find a solution?
    Marti Raudsepp
    @intgr
    Now that mypy 0.770 support is merged, any chance for a new release of django-stubs and drf-stubs?
    Marti Raudsepp
    @intgr
    For the record, version 1.5.0 was recently released: https://github.com/typeddjango/django-stubs/releases
    Tom
    @tmm

    Trying to run mypy (0.770) during pre-commit and getting the following error:

    setup.cfg:10: error: Error importing plugin 'mypy_django_plugin.main': No module named 'mypy_django_plugin'

    django-stubs 1.5.0
    django 3.0.4

    Jose Di Nunzio
    @jose.dinuncio_gitlab
    Missing library? Try import mypy_django_plugin using the same python interpreter invoked by your pre-commit hook, it should fail. If that's the case, pip install it for that interpreter.
    Nikita Sobolev
    @sobolevn
    Try to use --show-traceback option
    (kind of late, but better than never!)
    Dustin Wyatt
    @dmwyatt
    I'm sure I'm missing something obvious, but how do I avoid error: Missing type parameters for generic type "QuerySet" on custom QuerySet class definitions? just # type: ignore the line?
    Adrien Lemaire
    @AdrienLemaire
    Hi there. Is it possible to fix this mypy error when getting model classes from ContentType (to avoid recursive looping between files imports) ? https://i.imgur.com/ZiZq6Ct.png
    Kacper
    @kszmigiel

    Hello guys, I got this error while trying to run pytest:

    ~/P/django-stubs ❯❯❯ pytest
    ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
    pytest: error: unrecognized arguments: --mypy-ini-file=./test-data/plugins.ini --mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook
      inifile: /Users/kacperszmigiel/Projects/django-stubs/pytest.ini
      rootdir: /Users/kacperszmigiel/Projects/django-stubs

    Has anyone encountered this error and knows a fix?

    Kacper
    @kszmigiel
    Ok, it seems that I had so many Python versions installed on my machine that pytest went mad. Deleting them all and installing only 3.7 helped.
    Kacper
    @kszmigiel
    pdtilton
    @pdtilton
    I'm not sure if I'm missing something, but I get a mypy error when passing 'max_length' to a SlugField. It looks like the stub for SlugField is missing 'max_length' and 'min_length' parameters in init. https://github.com/typeddjango/django-stubs/blob/v1.5.0/django-stubs/forms/fields.pyi. I can submit an issue if it's not user error.
    sz-lesniak
    @sz-lesniak
    Hi, my project extensively takes advantage of *_id syntax to access foreign key IDs. Does django-stubs support typing for such expressions?
    One obvious but cumbersome solution would be to manually add [foreign_key]_id field hint for every ForeignKey in every model, but even then I'm not sure what the appropriate type hint should be.
    Andri Janusson
    @andrijan
    Hey people!
    Now that JSONField has moved from django.contrib.postgres.fields.JSONField to django.db.models in Django 3.1 (Under development) - how would you propose to continue for us using the development branch of Django?
    Just ignore it until it has been added to django-stubs?
    Melvyn Sopacua
    @melvyn-sopacua_gitlab

    So, this is hard to explain:

    from django.contrib.auth.models import Group
    from django.db import models
    
    class MyGroup(Group):
        pass
    
    
    class User(models.Model):
        groups = models.ManyToManyField(MyGroup)
    
    group = MyGroup()
    user = User()
    reveal_type(MyGroup.permissions)
    reveal_type(group.permissions)
    reveal_type(user.groups)
    mypy-test.py:13: note: Revealed type is 'django.db.models.fields.related_descriptors.ManyToManyDescriptor'
    mypy-test.py:14: note: Revealed type is 'django.db.models.manager.RelatedManager*[django.contrib.auth.models.Permission]'
    mypy-test.py:15: note: Revealed type is 'Any'

    Any idea what's happening here?

    Nathan Levin-Greenhaw
    @njlg
    Anyone know when we can expect django-stubs@1.6.0 to get released?