[Python-Dev] subclassing builtin data structures
Serhiy Storchaka
storchaka at gmail.com
Sat Feb 14 07:22:24 CET 2015
On 14.02.15 01:03, Neil Girdhar wrote:
> Now the derived class knows who is asking for a copy. In the case of
> defaultdict, for example, he can implement __make_me__ as follows:
>
> def __make_me__(self, cls, *args, **kwargs):
> if cls is dict: return default_dict(self.default_factory, *args,
> **kwargs)
> return default_dict(*args, **kwargs)
>
> essentially the caller is identifying himself so that the receiver knows
> how to interpret the arguments.
No, my idea was that __make_me__ has the same signature in all
subclasses. It takes exactly one argument and creates an instance of
concrete class, so it never fails. If you want to create an instance of
different class in the derived class, you should explicitly override
__make_me__.
More information about the Python-Dev
mailing list