Remove some unnecessary defer rounds#2252
Conversation
There was a problem hiding this comment.
I'm going to argue that the changes here improves correctness. Since the manager in the test comes from a function that specifies a manager as return type:
def LocalManager() -> models.Manager:
"""
Returns a manager instance of an inlined manager type that can't
be resolved.
"""
class InnerManager(models.Manager): ...
return InnerManager()This (now) assigns a type models.Manager[Any], the return type of the function. I would say that the previous behaviour did too much, since it tried to express that assigned an invalid manager. But to know that it had to draw conclusions from the function body and thus "override" the return type.
The plugin should now only consider calls of the format: objects = <Manager>.from_queryset(<QuerySet>)() or objects = <QuerySet>.as_manager() in this case
Change so that we don't trigger unnecessary defer rounds during manager creation via the `from_queryset` method call.
8ed6834 to
07503e6
Compare
|
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 |
Change so that we don't trigger unnecessary defer rounds during manager creation via the
from_querysetmethod call.Refs: