how should i do best to make a function interface that wraps a “private” class?
i have this function i want to use let’s call it func(), and the point is to expose it via package __init__, but the core functionality is done using a class, so it wraps a class and does some stuff
how should i best do this? i prefer not to write all the parameters twice since the PrivateClass will only ever be used internally.
my code below is how i do it now:
def PrivateClass:
def __init__(params):
self.takes = params.get("takes")
# and so on ...
def func(takes=None, a=None, bunch=None, of=None, parameters=None):
# do some stuff
params = locals()
PrivateClass.run(params)
the other way i can do it is by only using self.params.get(“mykey”) where i need it in the class.
additional question, when making a private class for internal use should it be started with a _, such as _PrivateClass?
please all give your opinion on the best way to do this!
Why is PrivateClass a class in the first place? Your use of the class in func doesn’t fit with the definition shown (you don’t instantiate the class, only use a static/class method with an argument seemingly intended for __init__), but there’s enough to suggest that PrivateClass should probably just be a function itself. (It can still be private; perhaps there is some difference in how the user would call func and how func would call the private implementation.)
to add more context, i wish i could write this as functions but i always needed to pass around tons of state to make it work, it is unreasonable to pass 6-7 args everywhere all the time.
therefore i have concluded, it’s best to write a function that has the relevant parameters (this will be the api that you import in the package) then it passes this on to class which does most of the work
the question of this topic is “how to make a function interface for a class the best way?” without writing all the parameters twice. I currently do it by passing locals(), then taking what i need from that.
additional note: it is private because the func does enough preparation that you would never want to use PrivateClass by yourself even if you could