I want to create a class that behaves like collections.defaultdict, without having the usage code specify the factory. EG: instead of
class Config(collections.defaultdict):
pass
this:
Config = functools.partial(collections.defaultdict, list)
This almost works, but
isinstance(Config(), Config)
fails. I am betting this clue means there are more devious problems deeper in also. So is there a way to actually achieve this?
I also tried:
class Config(Object):
__init__ = functools.partial(collections.defaultdict, list)
isinstance(Config(), collections.defaultdict)
? As long asConfig
is not a class,isinstance
will of course fail. As explicit type checks aren't common / recommended in python you might as well keep usingConfig
as above - it should work as intented in many cases. – Irrespirable