[Python-Dev] subclassing builtin data structures (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Sat Feb 14 07:22:24 CET 2015
- Previous message: [Python-Dev] subclassing builtin data structures
- Next message: [Python-Dev] subclassing builtin data structures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 makeme as follows:
def makeme(self, cls, *args, **kwargs): if cls is dict: return defaultdict(self.defaultfactory, *args, **kwargs) return defaultdict(*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.
- Previous message: [Python-Dev] subclassing builtin data structures
- Next message: [Python-Dev] subclassing builtin data structures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]