
On 10/21/2015 1:41 PM, Sven R. Kunze wrote:
On 21.10.2015 00:50, Chris Angelico wrote:
She recommends a massive superclass that's capable of any form of injection
Nope. She does not.
The "superclass" is not "massive" at all. It is even slimmer as orthogonal aspects are refactored out into separate entities. In fact, it makes it even easier to test and maintain these separate aspects (the core dev should be interested in that). Furthermore, it's, of course, up to debate which aspects should be injectable and which are not.
The dict class itself is, in a sense, a poor example for this discussion. It is a critical part of Python's infrastructure, involved in a large fraction of executed statements. It therefore needs to be as fast as possible. For CPython, this means a heavily optimized C implementation that disallows injection and that takes shortcuts like bypassing method lookups. This makes the usefulness of subclassing limited. Of course, before 2.2, dict (and other built-in types) could not even be subclassed. UserDict is the 'user base dict class', meant to be subclassed by users. A solution to UserDict being too slow could be a C accelerator that did not bypass method lookups. A revised UserDict could be designed for injection in the way being discussed. -- Terry Jan Reedy