On 14.02.15 03:12, Ethan Furman wrote:
The third choice is to use different specially designed constructor.
class A(int):
--> class A(int):
... def __add__(self, other):
... return self.__make_me__(int(self) + int(other))
... def __repr__(self):
... return 'A(%d)' % self
How would this help in the case of defaultdict? __make_me__ is a class method,
but it needs instance info to properly
create a new dict with the same default factory.
In case of defaultdict (when dict would have to have __add__ and like)
either __make_me__ == dict (then defaultdict's methods will return
dicts) or it will be instance method.
def __make_me__(self, other):
return defaultdict(self.default_factory, other)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com