python TypeError: __new__() missing 1 required positional argument: 'namespace'

modkzs

I try to initialize class using

tsf = TimeSeriesFeature(cut_avg, interval)

but I got TypeError: __new__() missing 1 required positional argument: 'namespace'.

The init code of TimeSeriesFeature is below:

class TimeSeriesFeature(BasicFeature):
    def __init__(self, cut_avg, interval):
        super().__init__()
        self.cut_avg = cut_avg
        self.interval = interval
        self.get_avg()

and BasicFeature init code:

class BasicFeature(ABCMeta):
    def __init__(self):
        self.times = {}
        self.avg = {}

and I'm using python3.5. Is there any mistake?

mbdevpl

The error you're getting is from the fact that instantiation of metaclass does not use it's __init__ method, but rather it's __new__ method which (excluding self) expects 3 arguments, last being said namespace.

As it stands now your class inherits from ABCMeta (which is a metaclass), therefore it is also a metaclass:

class BasicFeature(ABCMeta):
    ...

but I think you'd rather set ABCMeta as a metaclass of your class:

class BasicFeature(metaclass=ABCMeta):
    ...

That way your class becomes an ordinary class, with ABCMeta as it's metaclass.

If you'd like BasicFeature to be a abstract (in other words impossible to initialize) class, add an abstract method to it, like this:

class BasicFeature(metaclass=ABCMeta):

    @abstractmethod
    def get_avg():
        pass

and overload it in subclass without the @abstractmethod decorator:

class TimeSeriesFeature(BasicFeature):

    def get_avg():
        # ... some code
        # ... some code

Then, users who attempt to instantiate BasicFeature will get an error about get_avg() being abstract, but users who instantiate TimeSeriesFeature will not. More details available in the documentation

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python smtp TypeError: sendmail() missing 1 required positional argument: 'msg'

From Dev

python decorator TypeError missing 1 required positional argument

From Dev

TypeError on Python. Missing1 required positional argument

From Dev

Python TypeError: set() missing 1 required positional argument: 'value'

From Dev

TypeError: function missing 1 required positional argument: 'path' Flask Python

From Java

TypeError: Missing 1 required positional argument: 'self'

From Dev

Pygame TypeError: missing 1 required positional argument:

From Dev

Pygame - TypeError: Missing 1 required positional argument

From Dev

TypeError: func1() missing 1 required positional argument: 'self'

From Dev

missing 1 required positional argument

From Dev

TypeError: missing 1 required positional argument: 'self' but the class is instanciated

From Dev

TypeError: get_params() missing 1 required positional argument: 'self'

From Dev

TypeError: classify() missing 1 required positional argument: 'featureset'

From Dev

TypeError: insert() missing 1 required positional argument: 'string'

From Dev

Pandas DataFrame TypeError: quantile() missing 1 required positional argument: 'quantile'?

From Dev

TypeError: lemmatize() missing 1 required positional argument: 'word

From Dev

TypeError: __call__() missing 1 required positional argument: 'inputs'

From Dev

TypeError: <lambda>() missing 1 required positional argument: 'w'

From Dev

TypeError: on_message() missing 1 required positional argument: 'message'

From Dev

TypeError: delete() missing 1 required positional argument: 'indexPosition'

From Dev

tensorflow TypeError: ParseFromString() missing 1 required positional argument: 'serialized'

From Dev

TypeError: x missing 1 required positional argument: y

From Dev

TypeError: player_attack() missing 1 required positional argument: 'self'

From Dev

TypeError: cone() missing 1 required positional argument: 'height'

From Dev

TypeError: __init__() missing 1 required positional argument: 'id'

From Dev

TypeError: str() missing 1 required positional argument: 'self'

From Dev

TypeError: insert() missing 1 required positional argument: 'string'

From Dev

TypeError: askopenfilename() missing 1 required positional argument: 'root' In [ ]:

From Dev

TypeError: grid_configure() missing 1 required positional argument: 'self'

Related Related

  1. 1

    python smtp TypeError: sendmail() missing 1 required positional argument: 'msg'

  2. 2

    python decorator TypeError missing 1 required positional argument

  3. 3

    TypeError on Python. Missing1 required positional argument

  4. 4

    Python TypeError: set() missing 1 required positional argument: 'value'

  5. 5

    TypeError: function missing 1 required positional argument: 'path' Flask Python

  6. 6

    TypeError: Missing 1 required positional argument: 'self'

  7. 7

    Pygame TypeError: missing 1 required positional argument:

  8. 8

    Pygame - TypeError: Missing 1 required positional argument

  9. 9

    TypeError: func1() missing 1 required positional argument: 'self'

  10. 10

    missing 1 required positional argument

  11. 11

    TypeError: missing 1 required positional argument: 'self' but the class is instanciated

  12. 12

    TypeError: get_params() missing 1 required positional argument: 'self'

  13. 13

    TypeError: classify() missing 1 required positional argument: 'featureset'

  14. 14

    TypeError: insert() missing 1 required positional argument: 'string'

  15. 15

    Pandas DataFrame TypeError: quantile() missing 1 required positional argument: 'quantile'?

  16. 16

    TypeError: lemmatize() missing 1 required positional argument: 'word

  17. 17

    TypeError: __call__() missing 1 required positional argument: 'inputs'

  18. 18

    TypeError: <lambda>() missing 1 required positional argument: 'w'

  19. 19

    TypeError: on_message() missing 1 required positional argument: 'message'

  20. 20

    TypeError: delete() missing 1 required positional argument: 'indexPosition'

  21. 21

    tensorflow TypeError: ParseFromString() missing 1 required positional argument: 'serialized'

  22. 22

    TypeError: x missing 1 required positional argument: y

  23. 23

    TypeError: player_attack() missing 1 required positional argument: 'self'

  24. 24

    TypeError: cone() missing 1 required positional argument: 'height'

  25. 25

    TypeError: __init__() missing 1 required positional argument: 'id'

  26. 26

    TypeError: str() missing 1 required positional argument: 'self'

  27. 27

    TypeError: insert() missing 1 required positional argument: 'string'

  28. 28

    TypeError: askopenfilename() missing 1 required positional argument: 'root' In [ ]:

  29. 29

    TypeError: grid_configure() missing 1 required positional argument: 'self'

HotTag

Archive