Suppose I have the following functions:
class Foo:
@classmethod
def bar(cls, a, b): # do not want to use *args or **kwargs
return 'a b'
@classmethod
def advanced_bar(cls, a, b): # do not want to use *args or **kwargs
ab = cls.bar(a, b)
return ab.upper()
And my question is: how do I, in a streamlined, somewhat robust way, capture the calling scope args as a *args
-type object and write advanced_bar
as:
@classmethod
def bar(cls, a, b): # did not define any *args or *kwargs bins for arguments to overflow into
return 'a b'
@classmethod
def advanced_bar(cls, a, b):
...
x = 'y' # added in a local variable
ab = cls.bar(*this_functions_args)
return ab.upper()
Where I added some extra things that I think will break the jankiest solution to this question.
Specifically, I want to avoid the redundant, verbose noise:
def advanced_bar(cls, a, b): # specifically defined args (I do not want to accept *args or **kwargs here)
args = (a,b)
ab = cls.bar(*args) # haven't really gained anything
return ab.upper()
So, in light of that solution, I think a decorator is a sufficing answer.
The reason why I am not using *args
and **kwargs
at the entry point of the functions is to leverage the IDE.
I think verbosity is very important in the function signature, and that is my personal style -- I think it is a mistake to drop names from the interface.
So, I am looking for a way to halve my cake and eat it too: it seems like there should be such a way.
One way to have explicitly named function arguments, no *args
or **kwargs
holes in the code, define as many local variables before hand as desired, and have the *args
syntactical tool might be to decorate the function, internally, somehow...
# alternatively, I can use the idiom
def foo:
args = locals()