[issue16545] ast.FunctionDef sets a bad value for kw_defaults when keyword-only arguments present

Brett Cannon report at bugs.python.org
Fri Nov 23 23:40:46 CET 2012


New submission from Brett Cannon:

When there are no keyword-only arguments, the value of kw_defaults for FunctionDef is []. But when keyword-only arguments are present with no default values, it becomes [None]. That's bad as every other value in FunctionDef has a default of [] when there is nothing of value there (currently you can trust that [None] means no default value as None isn't anything in the AST).


>>> ast.dump(ast.parse('def func(*, name):pass'))
"Module(body=[FunctionDef(name='func', args=arguments(args=[], vararg=None, varargannotation=None, kwonlyargs=[arg(arg='name', annotation=None)], kwarg=None, kwargannotation=None, defaults=[], kw_defaults=[None]), body=[Pass()], decorator_list=[], returns=None)])"

>>> ast.dump(ast.parse('def func(name):pass'))
"Module(body=[FunctionDef(name='func', args=arguments(args=[arg(arg='name', annotation=None)], vararg=None, varargannotation=None, kwonlyargs=[], kwarg=None, kwargannotation=None, defaults=[], kw_defaults=[]), body=[Pass()], decorator_list=[], returns=None)])"

----------
components: Library (Lib)
keywords: 3.3regression
messages: 176260
nosy: brett.cannon
priority: normal
severity: normal
stage: test needed
status: open
title: ast.FunctionDef sets a bad value for kw_defaults when keyword-only arguments present
versions: Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16545>
_______________________________________


More information about the Python-bugs-list mailing list