> We should have a mechanism that collects the current function or method's 
> parameters into a dict, similar to the way locals() returns all local 
> variables.

Maybe I'm missing something here, but how about... `locals`? It works exactly 
as you hope:

```
def __init__(self, argument_1, argument_2, argument_3=None):
    for name, value in locals().items():
        if name != "self":
            setattr(self, name, value)
```

It's a fairly common idiom to just collect `locals()` on the first line of a 
function or method with lots of arguments, if they're just going to be passed 
along or processed directly. That way, you get the flexibility of `**kwargs`, 
but without losing tab-completion, annotations, helpful `help`, and other 
introspection.

```
>>> def foo(bar, baz=7, *spam, eggs, cheese=7, **other):
...     kwargs = locals()
...     # Do some stuff...
...     return kwargs  # Just to see what's in here!
... 
>>> foo(5, eggs=6, blah='blah')
{'bar': 5, 'baz': 7, 'eggs': 6, 'cheese': 7, 'spam': (), 'other': {'blah': 
'blah'}}
```

Brandt
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FUH5ZS5NPR6673PNRP5BBV2W2DT7727K/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to