Skip to content

Conversation

@mkurnikov
Copy link
Member

No description provided.

@mkurnikov mkurnikov force-pushed the newsemanal-progress branch from 1419b14 to e6aba81 Compare June 19, 2020 15:02
@mkurnikov
Copy link
Member Author

mkurnikov commented Jun 19, 2020

Ok, this is what I imagined refactoring would be like.

Those are some descriptions of the PR:

  1. Drop support for the Manager and QuerySet without annotations. So, for your
class MyModel(models.Model):
    mymanager = MyManager()

you'll have to explicitly change the manager's instantiation to the MyManager[MyModel], otherwise typechecker will give an error.

Django 3.1 will have native support for that via django/django@578c03b
For Django 2.2 and 3.0 user would need to use this helper https://github.com/typeddjango/django-stubs/pull/366/files#diff-cd31ac9ed2da033b1967049827559013R1

from mypy_django_plugin.lib import make_classes_generic
make_classes_generic(MyManager)

class MyModel(models.Model):
    mymanager = MyManager['MyModel']()
  1. For the reason above, testing for both 2.2 and 3.0 test suites will be dropped. Stubs compatibility should be tested with the actual Django code, using
    https://github.com/ambv/retype
    https://github.com/google/pytype/tree/master/pytype/tools/merge_pyi
    or custom stubs merger based on https://libcst.readthedocs.io/en/latest/codemods.html#libcst.codemod.visitors.ApplyTypeAnnotationsVisitor
    (that's for @kszmigiel, I won't have the bandwidth)

  2. This PR drops support for the Manager.from_queryset() and Queryset.as_manager(). Not because it's not implementable, just I don't have enough bandwidth to finish it. I imagine @kszmigiel would implement those on top of this PR.

  3. API for plugin callbacks will be class-based, see https://github.com/typeddjango/django-stubs/pull/366/files#diff-a27b71ebfd9f3481ef4c189ac74fe6d7R9 for an example.

Before I move all the remaining code to the new API, I'd like to have others confirm/reject this proposal.

@sobolevn
Copy link
Member

You have my approval 👍

Thanks a lot for working on this!
Amazing!

@sobolevn
Copy link
Member

@kszmigiel you can take a look and get familiar with the code when you have the time!

@sobolevn
Copy link
Member

sobolevn commented Aug 7, 2020

@mkurnikov can you please rebase this branch on current master?

@intgr intgr added the stale Pull requests that have been out of date or unmergeable for a long time. label Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Pull requests that have been out of date or unmergeable for a long time.

Development

Successfully merging this pull request may close these issues.

5 participants