Python classes cannot inherit from any type, just from other classes. However, automatic delegation (via __getattr__ and __setattr__) can provide pretty much the same functionality as inheritance (without such limits, and with finer-grained control).
Python, 30 lines
The split between 'class' and 'type' in Python is often bemoaned -- in particular, it does not allow classes we write to inherit from builtin types we might easily want to extend and tweak, such as, e.g., the file-object type.
However, it ain't so bad...! We can easily code a class each of whose instances holds an instance of the type we're "wrapping" (extending and/or tweaking); thanks to __getattr__ and __setattr__, it's easy to arrange for anything we don't want to have know about to be automatically delegated to the instance we're holding. The recipe exemplifies this through an UppercaseFile class that arranges for anything written to be uppercased first, while otherwise transparently delegating anything else to the file object it holds; but this technique really comes in handy for ALL sort of wrappers.
(Not JUST wrappers over built-in types, actually; delegation, while slightly less automatic than inheritance, IS more powerful in terms of fine-grained control on operations of interest -- inheritance will most often suffice, and it's easier to use [and may perform better], but it's better to also keep automatic delegation in one's bag of tricks, just in case...).
Note: wrapping will NOT, of course!, work with client code that, one way or another, tests with "isinstance(anobj, atype)" [or, worse, checks that "type(anobj)==atype" -- SHUDDER!] -- but then, in such cases it is the client code that's breaking polymorphism, and should be rewritten...! _Point to remember_: DO NOT code type-tests in your own client-code -- you do NOT really need them anyway!-)