On 05.05.20 15:35, Dan Sommers wrote:

On Tue, 5 May 2020 23:06:39 +1000
Steven D'Aprano <st...@pearwood.info> wrote:

... help me solve the DRY problem for module-level functions:

     def function(spam, eggs, cheese, aardvark):
         do stuff
         call _private_function(spam, eggs, cheese, aardvark)

since this bites me about twice as often as the `self.spam = spam`
issue.

(That's not me being snarky by the way, it's a genuine question:
dataclasses are a mystery to me, so I don't know what they can and can't
do.)
Lisp macros have a "&whole" feature that captures the entire collection
of arguments to the macro:

     http://clhs.lisp.se/Body/03_dd.htm

Perhaps Python could adopt something similar?  Unlike *args and
**kwargs, &whole captures all of the parameters, not just the
non-positional, non-named ones.  The idea would be something like this:

     def function(spam, eggs, cheese, aardvark, &whole):
         do_stuff
         _private_function(&whole)

which would call _private_function as function was called.

What about a way for overloading function signatures? The arguments are
then bound to both signatures and the function has access to all the
parameters. For example:

    def function(spam, eggs, cheese, aardvark) with (*args):
        ...  # do stuff
        _private_function(*args)

Calling `function(1, 2, 3, 4)` results in `spam, eggs, cheese, aardvark
= 1, 2, 3, 4` and `args = (1, 2, 3, 4)`.
_______________________________________________
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/OHGIK5YHET6YUANFDT7RRXRT47AIAYM5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to