This is related to "Extends is evil" vs. OCP? but separate because the idea of "implement the interface" doesn't exist in Python.
I'm writing a class to pull some data off a webpage. It's going to need to hold on to a cookie for authentication, so I'm going to use a requests.Session
object in some form. I'm never sure how to approach this -- what's the appropriate choice here?
class FooFetcher(requests.Session):
def __init__(self):
super.__init__()
or
class FooFetcher(object):
def __init__(self):
self.session = requests.Session()
?
The former seems to end up with FooFetcher
having way more public methods than it needs to. The latter looks like it might be unnecessarily convoluted, since pretty much every method of FooFetcher
is going to involve a call to a method of that Session
object, plus maybe some parsing of JSON that it finds.