On Tue, 5 May 2020 23:06:39 +1000 Steven D'Aprano <steve@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. No, Lisp macros are not Python function calls. No, I'm not proposing that exact syntax. No, I haven't thought it through. Yes, it borders on magic, and may impinge on implicit vs. explicit. But evidently, Steven and I share this particular pattern, although I never considered it enough of a problem to "solve." Dan -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan