4

I tried some code like:

class StaticPageStage(StageBase):
    key = Segments.STATICPAGE
    _preprocessors = [FacebookGraphStage(), ]
    
    def __init__():
        pass
    
    def process(self, data):
        data = self._preprocess(data)
        return self.handle_results(tuple(x for x in data))

but I get an exception that says TypeError: __init__() takes no arguments (1 given). What is wrong, and how do I fix it?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
marr75
  • 5,666
  • 1
  • 27
  • 41

3 Answers3

8

You need to add the default self parameter to __init__:

def __init__(self):
Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54
3

init must have at least one argument in its signature:

def __init__(self):
    pass

Here the error comes probably from FacebookGraphStage. Check its init method (and the other ones in your files) to solve the problem

Simon Bergot
  • 10,378
  • 7
  • 39
  • 55
1

You always use the self argument within function definitions inside of classes, even if the function never takes in a parameter. self is passed to all of the functions as a first parameter, so the error is saying that your function __init__ isn't accepting it.

Here's some (hopefully) working code:

class StageBase(object):
    key = Segments.NONE
    _preprocessors = []

    def __init__(self):
        self.closing = False
        self.working = False
        self._que = None
        self._working_lock = None
        self._que_lock = None

    #whole bunch of other methods


class StaticPageStage(StageBase):
    key = Segments.STATICPAGE
    _preprocessors = [FacebookGraphStage(), ]

    def __init__(self):
        pass

    def process(self, data):
        data = self._preprocess(data)
        return self.handle_results(tuple(x for x in data))
Blender
  • 289,723
  • 53
  • 439
  • 496