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?
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.
Comments