Handle optional parameters that were never supported

Previously, pycodestyle never introspected the argument names for
classes except to require that ``tree`` be an argument it could pass.
For Flake8 3.0, we lifted that restriction, but old plugins seem to
have cargo-culted their __init__ signature to be

    def __init__(self, tree, builtins=None):

For some yet unknown reason. This was causing an AttributeError. By
updating flake8.utils.parameters_for to return a dictionary that
indicates whether the parameter is required or not, we can side-step
this by simply ignoring the parameter if it has a default value and
we cannot provide it.

Closes #151
This commit is contained in:
Ian Cordasco 2016-06-28 09:36:24 -05:00
parent ec2e601cbf
commit 2d3e277b1e
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
5 changed files with 49 additions and 20 deletions

View file

@ -102,17 +102,22 @@ def test_parameters_for_class_plugin():
plugin = plugin_manager.Plugin('plugin-name', object())
plugin._plugin = FakeCheck
assert utils.parameters_for(plugin) == ['tree']
assert utils.parameters_for(plugin) == {'tree': True}
def test_parameters_for_function_plugin():
"""Verify that we retrieve the parameters for a function plugin."""
def fake_plugin(physical_line, self, tree):
def fake_plugin(physical_line, self, tree, optional=None):
pass
plugin = plugin_manager.Plugin('plugin-name', object())
plugin._plugin = fake_plugin
assert utils.parameters_for(plugin) == ['physical_line', 'self', 'tree']
assert utils.parameters_for(plugin) == {
'physical_line': True,
'self': True,
'tree': True,
'optional': False,
}
def read_diff_file(filename):