[Python-Dev] subclassing builtin data structures (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Sat Feb 14 07:01:40 CET 2015
- Previous message: [Python-Dev] subclassing builtin data structures
- Next message: [Python-Dev] PEP 471 (scandir): Add a new DirEntry.inode() method?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.makeme(int(self) + int(other)) ... def repr(self): ... return 'A(%d)' % self How would this help in the case of defaultdict? makeme 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)
- Previous message: [Python-Dev] subclassing builtin data structures
- Next message: [Python-Dev] PEP 471 (scandir): Add a new DirEntry.inode() method?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]