-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Description
Bug report
Bug description:
*args and **kwargs have an empty tuple and dictionary respectively as default values as shown below:
def func(*args):
print(args, type(args))
func()
# () <class 'tuple'>def func(**kwargs):
print(kwargs, type(kwargs))
func()
{} <class 'dict'>Then, setting a default value to *args and **kwargs gets the error messages as shown below. I think the error messages should explain more clearly because Python doc doesn't explain *args and **kwargs are the optional parameters which have the immutable default values () and {} respectively and var-keyword argument and var-keyword argument should be var-keyword parameter and var-keyword parameter:
def func(*args='Hello'):
pass
# ErrorSyntaxError: var-positional argument cannot have default value
def func(**kwargs='Hello'):
pass
# ErrorSyntaxError: var-keyword argument cannot have default value
So, the error messages should be like belolw:
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value
()
SyntaxError: var-keyword parameter's default value cannot be changed because it has the immutable default value
{}
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status