typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.52k stars 425 forks source link

Remove some unnecessary defer rounds #2252

Open flaeppe opened 1 week ago

flaeppe commented 1 week ago

Change so that we don't trigger unnecessary defer rounds during manager creation via the from_queryset method call.

Refs:

flaeppe commented 2 days ago

To clarify a little bit more; previously the plugin could tell mypy to defer on e.g. a case like this:

def not_a_manager() -> Any: ...

class SomeModel(models.Model):
    objects = not_a_manager()

Deferring isn't gonna make it a more of a manager. The changed code looks for a more narrow/specific case that we want and can handle that comes from from_queryset. For any other situation we now just continue without deferring.

flaeppe commented 19 hours ago

@sobolevn, @intgr would any of you guys mind checking this out? I'm suspecting it could improve a couple of errors in #1023 (though I have no proof that it will)