On 2015-10-20 18:50, Steven D'Aprano wrote:
Take dict. One nuisance with inheriting from dict is that it isn't sufficient to override __setitem__, you also have to override update and clear as well. And possibly others -- the exact set of which methods depend on which other methods are not documented in the dict API. Given an arbitrary class, how can you possibly tell which methods you need to override, or even which methods are*safe* to override?
I've always considered that (and related problems) to be one of Python's warts. And, as you say, it's a documentation flaw.
It's true that it's easy to write classes with poorly documented APIs, which makes them hard to extend because you don't know how they work. But I don't think that means subclassing is not a good idea. It means writing classes with clearly-specified APIs is a good idea.