Description
Summary
When adding a plugin which registers a transform it registers and calls the transform as expected, but when enabling multiple jobs, the transform doesn't get called resulting in a different result than expected.
The plugin seems to be loaded fine, but the transform is not triggered.
The expected behavior is to have the linting result be the same regardless of the number of jobs.
Pylint version
> python -m pylint --version
pylint 2.8.3
astroid 2.5.6
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
MWE
With the content of mwe.py
being:
# PLUGIN
import astroid
def register(_):
# Needed for registering the plugin.
pass
def has_extra_arg_decorator(node):
return node.decorators and any(d.name == 'class_wrapper' for d in node.decorators.nodes)
def add_extra_arg(node):
print('transform triggered!')
init_function = node.getattr('__init__')[0]
new_arg = astroid.nodes.AssignName('new_arg', parent=init_function.args)
init_function.args.args.insert(1, new_arg)
# MRE
def class_wrapper(cls):
"""
Class decorator which adds an extra argument to __init__
"""
init_func = cls.__init__
def wrapped_init(self, new_arg, *args, **kwargs):
print(new_arg)
init_func(self, *args, **kwargs)
cls.__init__ = wrapped_init
return cls
@class_wrapper
class CoolClass():
def __init__(self):
print('__init__')
if __name__ == '__main__':
instance = CoolClass('123')
else:
astroid.MANAGER.register_transform(astroid.ClassDef, add_extra_arg, has_extra_arg_decorator)
print('plugin registered!')
You get the following error when running pylint without plugins:
> python -m pylint -E mwe.py
************* Module mwe
mwe.py:42:15: E1121: Too many positional arguments for constructor call (too-many-function-args)
This is most likely since it can't figure out what the decorator is doing (similar to #259 but for the class decorator).
If we enable the plugin which adds the arg back using the transform (since we can't use signature-mutators
as it doesn't seem to work as expected here) we see that the error disappears
> python -m pylint -E --init-hook="import sys; sys.path.insert(0, '.')" --load-plugins mwe mwe.py
plugin registered!
transform triggered!
If we however increase the number of jobs, we see that plugin is registered, but the transform not triggered, resulting in the error returning
> python -m pylint -j2 -E --init-hook="import sys; sys.path.insert(0, '.')" --load-plugins mwe mwe.py
plugin registered!
************* Module mwe
mwe.py:42:15: E1121: Too many positional arguments for constructor call (too-many-function-args)