I am familiar with the concept of Abstract Base Classes (ABC's), as providing sets of properties of the builtin objects, but I don't have really any experience working with them. I can see that there's a Mapping
ABC, and a MutableMapping that inherits from it, but I don't see a .fromkeys()
method (the only thing missing off the top of my head.)
Would I be able to craft a dict with purely ABC's? What would that look like? Would that amount to nearly the same thing as subclassing dict
? Would there be any benefit to doing that? What would be the use-case?
Would I be able to craft a dict with purely ABC's?
No. Subclassing an ABC requires you to implement its interface; for example, Mapping
requires you to implement __getitem__
, __iter__
, and __len__
. The mixin methods provide default implementations for certain things in terms of the parts you need to implement, but you still need to provide the core. Mapping
won't automatically provide a hash table or BST implementation for you.