diff --git a/parso/python/__init__.py b/parso/python/__init__.py index 4e68952..dbbc6d6 100644 --- a/parso/python/__init__.py +++ b/parso/python/__init__.py @@ -47,9 +47,7 @@ def load_grammar(version=None): return load_grammar() -def parse(code=None, path=None, grammar=None, error_recovery=True, - start_symbol='file_input', cache=False, diff_cache=False, - cache_path=None): +def parse(code=None, **kwargs): """ If you want to parse a Python file you want to start here, most likely. @@ -70,6 +68,21 @@ def parse(code=None, path=None, grammar=None, error_recovery=True, :return: A syntax tree node. Typically the module. """ + # Wanted python3.5 * operator and keyword only arguments. + path = kwargs.pop('path', None) + grammar = kwargs.pop('grammar', None) + error_recovery = kwargs.pop('error_recovery', True) + start_symbol = kwargs.pop('start_symbol', 'file_input') + cache = kwargs.pop('cache', False) + diff_cache = kwargs.pop('diff_cache', False) + cache_path = kwargs.pop('cache_path', None) + + if kwargs: + raise TypeError( + "parse() got an unexpected keyword argument '%s'" + % next(iter(kwargs))) + + # Start with actual code. if code is None and path is None: raise TypeError("Please provide either code or a path.") diff --git a/test/test_parser.py b/test/test_parser.py index 051387a..c12a5f7 100644 --- a/test/test_parser.py +++ b/test/test_parser.py @@ -178,3 +178,8 @@ def test_open_string_literal(code): module = parse(code) assert module.get_code() == code assert module.end_pos == end_pos == module.children[1].end_pos + + +def test_too_many_params(): + with pytest.raises(TypeError): + parse('asdf', hello=3)