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

@ -114,13 +114,17 @@ def test_check_physical_error(error_code, line, expected_indent_char):
@pytest.mark.parametrize('params, args, expected_kwargs', [
(['blank_before', 'blank_lines'], None, {'blank_before': 0,
'blank_lines': 0}),
(['noqa', 'fake'], {'fake': 'foo'}, {'noqa': False, 'fake': 'foo'}),
(['blank_before', 'blank_lines', 'noqa'],
({'blank_before': True, 'blank_lines': True},
None,
{'blank_before': 0, 'blank_lines': 0}),
({'noqa': True, 'fake': True},
{'fake': 'foo'},
{'noqa': False, 'fake': 'foo'}),
({'blank_before': True, 'blank_lines': True, 'noqa': True},
{'blank_before': 10, 'blank_lines': 5, 'noqa': True},
{'blank_before': 10, 'blank_lines': 5, 'noqa': True}),
([], {'fake': 'foo'}, {'fake': 'foo'}),
({}, {'fake': 'foo'}, {'fake': 'foo'}),
({'non-existent': False}, {'fake': 'foo'}, {'fake': 'foo'}),
])
def test_keyword_arguments_for(params, args, expected_kwargs):
"""Verify the keyword args are generated properly."""