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)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4