3 ms·
To be fair, I have come prefer approaching the problem stated in the link in the exact opposite direction. Specifically the part about having a collection of fu
by fluidcruft 3y ago
To be fair, I have come prefer approaching the problem stated in the link in the exact opposite direction. Specifically the part about having a collection of functions with signatures that are similar/identical. The example in the post is of a simple signature, but if you have more complex (and long) signatures and a bunch of functions that use them, it might be worth thinking about replacing the argument list with a frozen dataclass.
@dataclass(frozen=True)
class MyArguments:
a: int,
b: str,
c: list = None
def func1(self):
...
def func2(self):
...
etc. You can also sprinkle in @property and functools things like @cached, @cached_property when desired. It also lets you create functions that transform MyArguments into different MyArguments.
- sanderjd 3y agoYeah I'm with you here too.
- fluidcruft 3y agoThe struggle to figure out what the hell to name MyArguments is real. But that's also true about picking a name for the dict-of-functions-that-have-a-similar-weird-signature. :D