Message 81210 - Python tracker (original) (raw)

Agreed (in principle). However, in practice the subtleties of override order must be documented (and a method of implementation must be established!!!) Consider:

class A: ... pass ... class C: ... metaclass = abc.ABCMeta ... class D: ... metaclass = abc.ABCMeta ... C.register(A) D.register(A) @generic ... def pprint(obj): ... print "Base", str(obj) ... @pprint.register(C) ... def pprint_C(obj): ... print "Charlie", obj ... @pprint.register(D) ... def pprint_D(obj): ... print "Delta", obj ... pprint(A())

What should be printed? A() is a C and a D, but which takes precedence? There is no concept of a MRO for ABCs, so how would the "correct" answer be defined? "Neither" may not be perfect, but at least it's clearly defined. Relying on order of registration for overloads of the generic function seems to me to be unacceptable, before anyone suggests it, as it introduces a dependency on what order code is imported.

So while the theory makes sense, the practice is not so clear. Respecting ABCs seems to me to contradict the "simple" aspect of simplegeneric, so a documented limitation is appropriate.

(But given the above, I'm more inclined now to leave the name as "simplegeneric", precisely to make this point :-))