Reputation: 3358
I was reading the code for the Python intervaltree
module and saw the following code, (source code here):
class Interval(namedtuple('IntervalBase', ['begin', 'end', 'data'])):
__slots__ = () # Saves memory, avoiding the need to create __dict__ for each interval
def __new__(cls, begin, end, data=None):
return super(Interval, cls).__new__(cls, begin, end, data)
It doesn't seem to do anything extra in the __new__
function, so what is the purpose of overwriting it here?
Any help will be really appreciated! Thank you!
Upvotes: 4
Views: 72
Reputation: 362627
The parent class is:
namedtuple('IntervalBase', ['begin', 'end', 'data'])
The parameters begin
, end
, and data
are all required parameters here.
In Interval
, the argspec has changed: the data
is now optional and defaults to None
.
Upvotes: 5