Description
Changing astroid version from 1.4.9 to 1.5.0 our pylint run time significantly increased. We managed to establish that the bulk of the time was spent inferring the use of Manager.from_queryset
in our Django code - e.g.
class MyQuerySet(QuerySet):
pass
class MyManager(Manager.from_queryset(MyQuerySet)):
pass
My knowledge of astroid is limited so I don't know exactly what it's doing but we managed to write a hacky pylint plugin to workaround the issue:
from astroid import MANAGER, nodes, inference_tip, Uninferable
def predicate(call):
return getattr(call.func, 'attrname', '') == 'from_queryset'
def transform(self, context=None):
return iter([Uninferable])
def register(linter):
MANAGER.register_transform(nodes.Call, inference_tip(transform), predicate)
The run time went from ~570 seconds to ~160 seconds.
I'm pretty sure astroid wasn't managing to correctly infer the method anyway so I don't think this actually changes anything.
The workaround is good enough for now but I thought I'd post the details here in case someone else runs into the same issue we had. I can't provide our codebase as an example but this is the source of the code in Django https://github.com/django/django/blob/cf8fc4797458b2c788ecf0be0afca6b0512ce1c0/django/db/models/manager.py#L165.