Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Aleksander Vognild Burkow
    @aleksanb
    then i've enable mypy in the plugin settings
    and set the mypy path explicitly to the binary like this /Users/aleksandervognildburkow/.virtualenvs/app-SIjAPd74/bin/mypy
    then, you have to have the root folder of your vscode project be the same as where your mypy.ini lives
    where my plugin section in that file looks like
    [mypy.plugins.django-stubs]
    django_settings_module = 'hyre.settings'
    SHxKM
    @SHxKM
    @aleksanb are you saying you have it working with real time warnings?
    I don’t understand what you mean by “set the mypy path explicitly to the binary” - in VSCode settings?
    Anthony Ricaud
    @rik

    @rik I usually just annotate all views with my custom request class

    @mkurnikov That's what I ended up doing, thanks

    Maksim Kurnikov
    @mkurnikov
    @silviogutierrez I'll try to find time on the weekend to finish remaining issues and release.

    @tomleo_twitter

    Has anyone written a stub for model_utils Choices?

    Considering this one incoming https://docs.djangoproject.com/en/dev/releases/3.0/#enumerations-for-model-field-choices, wouldn't it be redundant?

    Aleksander Vognild Burkow
    @aleksanb
    in the vscode python plugin in settings there's a setting called mypy path, set this to the full path like /Users/aleksandervognildburkow/.virtualenvs/app-SIjAPd74/bin/mypy based on whatever install mechanism you've chosen
    yes it works with realtime warning
    SHxKM
    @SHxKM
    @aleksanb - Thanks a lot for taking the time to help. It didn't work for my virtualenv but I started a dummy project with pipenv and your instructions worked (even without specifying the mypyPath explicitly). I'm not sure if virtualenv is to blame at this point, or something else with my main project.
    Aleksander Vognild Burkow
    @aleksanb
    probably something with the virtualenv then
    Nikita Sobolev
    @sobolevn
    @mkurnikov congrats on releasing 1.2.0! :tada:
    Seth Yastrov
    @syastrov
    Yes, nice job! I really like the rewrite to make use of Django's model metadata
    Maksim Kurnikov
    @mkurnikov
    Thanks=)
    Maksim Kurnikov
    @mkurnikov
    Just so you know, there's some discussion happening here
    django/deps#65
    Aleksander Vognild Burkow
    @aleksanb
    very cool!
    Good luck in the process, i hope it succeeds.
    Luís Rodrigues
    @lfrodrigues
    hello everyone,
    I just started testing django-subs. Some of my models inherit a model that defines some fields. What would be the correct way to make this work ?
    class BaseAbstractModel(models.Model):
        created_datetime = models.DateTimeField(_('Created at'), auto_now_add=True)
        updated_datetime = models.DateTimeField(_('Last update at'), auto_now=True)
    
        objects = models.Manager()
    
        class Meta:
            abstract = True
    Luís Rodrigues
    @lfrodrigues

    in my inherited model I have

    class LoanProduct(BaseAbstractModel):
        id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)  # noqa
    
        name = models.TextField()
        slug = models.SlugField(unique=True)

    and errors:

    src/loan/models.py:22: error: Need type annotation for 'id'
    src/loan/models.py:24: error: Need type annotation for 'name'
    src/loan/models.py:25: error: Need type annotation for 'slug'
    if I put
    class LoanProduct(BaseAbstractModel, models.Model):
    everything works but from what I read above and in ticket #68 this should no be required
    Luís Rodrigues
    @lfrodrigues
    sorry to bother you guys, was running outside my project directory
    it's working fine now, maybe would make sense to add in the docs how a newbie can run mypy in a django project
    Konstantin Alekseev
    @kalekseev
    Hi guys, could someone fix tests in rest framework stubs and release new version with mypy<0740, the tests are broken because QuerySet used with two generic params while django-stubs QuerySet has one.
    Nikita Sobolev
    @sobolevn
    Thanks a lot! I am reviewing it at the moment
    Nikita Sobolev
    @sobolevn
    @kalekseev please, check it out: typeddjango/djangorestframework-stubs#41
    Silvio
    @silviogutierrez

    I'm noticing objects isn't quite typed correctly. In the simplest case

    # models.py
    from django.db import models
    
    
    class MyModel(models.Model):
        field = models.CharField(max_length=100)
    
    
    # views.py
    from . import models
    
    
    def my_view() -> None:
        instance = models.MyModel.objects.all()
        instance = models.MyModel.objects.first()  # correct, no error, revealed type is Union[MyModel, None]
        instance = models.MyModel.objects.method_that_does_not_exist()  # no error, should error out ,revealed type is Any
        instance = models.MyModel.ojects.method_that_does_not_exist()  # correctly errors out saying that ojects (misspelled) does not exist on Type[MyModel].

    This applies to mypy 0.720 with stubs 1.1, and mypy 0.730 with stubs 1.2

    Michał Simonienko
    @Symonen
    Hey guys mypy just telling me that I need to type model fields? It is supposed to be like that?
    Michał Simonienko
    @Symonen
    Okay I see that it is an error. When you are inheriting from Abstract model then it is not working
    Konstantin Alekseev
    @kalekseev
    @sobolevn tested on one project, no regressions found. BTW what do you think about adding pre-commit to the projects, I see several PRs where people forget to run linters eg. issue, also we can benefit from using end-of-file-fixer linter, that would prevent diffs like that.
    Nikita Sobolev
    @sobolevn
    @kalekseev the thing with pre-commit is that people forget to install the hook :)
    I am all positive about other suggestions though
    A little bit offtopic, but still closely related. I have started a new project to write short and typed lamdbas like so: _ + 2 which equals to lambda x: x + 2
    Link: https://github.com/dry-python/lambdas There are still a lot of polishing required and some major features to be done. But, early feedback is welcome!
    Nikita Sobolev
    @sobolevn
    @silviogutierrez can you please open a new issue, so we can discuss it there?
    Silvio
    @silviogutierrez
    @sobolevn : absolutely.
    Silvio
    @silviogutierrez
    @sobolevn : here you go. typeddjango/django-stubs#213
    Konstantin Alekseev
    @kalekseev
    @sobolevn so what's the downside of having pre-commit and doc line "install git hooks or run linter before push"? pre-commit run -a can be used as a linter script replacement.
    TJ DeVries
    @tjdevries
    hey @lfrodrigues did you solve this just by running mypy from within the folder where you django project is defined? I'm wondering if I can fix this without doing that. We have a core/ folder that has non-Django specific library code, and a web/ folder where Django stuff is defined. So I can't just run the stuff from within web/ cause then it can't find the stuff that I have in core/
    cowlicks
    @cowlicks
    This error seems incorrect: utils.py:21: error: "Model" has no attribute "__name__" where Model is from django.db.models.Model
    cowlicks
    @cowlicks
    nvm I hadn't added the plugin to mypy.ini
    Fabian Schlager
    @ghtyrant

    I have issues deriving from Manager in my Django project:

    from django.db import models
    
    
    class MyManager(models.Manager['MyModel']):
        pass
    
    
    class MyModel(models.Model):
        pass

    This causes my Python (3.6) to fail with TypeError: 'type' object is not subscriptable

    django-stubs is installed via pipenv, version is 1.2.0
    Fabian Schlager
    @ghtyrant
    On the other hand, if I simply derive from models.Manager (without type parameter), mypy complains about a missing type parameter. So my current workaround is to tell mypy to ignore this line.
    Maksim Kurnikov
    @mkurnikov
    @ghtyrant yeah, you need either to monkeypatch __class_getitem__ for manager, or wait for relevant DEP to be accepted
    Fabian Schlager
    @ghtyrant
    Thank you @mkurnikov ! I will disable type checking for this line for now and wait for the DEP
    Jasper Koops
    @Jasper-Koops

    I' ve written a number of tests where I need to pass an invalid Object.ID which I solved by incrementing the id of the last valid instance like so:

    invalid_academy_id: int = Academy.objects.last().id + 100

    However, this is causing mypy-django to trip up and I'm a bit at a loss on how to solve this. Mypy considers the Academy.object.last() to be Optional and as such raises the following errors:

    api/tests/test_utils.py:106: error: Unsupported operand types for + ("AutoField[Union[Combinable, int, str], int]" and "int")
    
    api/tests/test_utils.py:106: note: Left operand is of type "Union[AutoField[Union[Combinable, int, str], int], Any]"

    However, even removing the :int typing fails to remove the error. I could ofcourse ignore the error - but that seems like an inadequate solution. Has anyone run into these kind of errors (fetching parameters from objects which are technically optional but which you know to exist) and - if so - how did you solve them?

    Seth Yastrov
    @syastrov

    you don't actually know that there is any object returned by last() -- if there are no rows in the table :)
    You could do:

    obj = Academy.objects.last()
    assert obj is not None
    my_id = obj.id # Now mypy knows that obj is not None

    Then you will also get a run-time assertion if the object is None

    Alternatively, you could just tell mypy that you know better about the type: obj = cast(Academy, Academy.objects.last()) but it's kind of unsafe