Message81210
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 :-)) |
|
Date |
User |
Action |
Args |
2009-02-05 11:59:37 | paul.moore | set | recipients:
+ paul.moore, doerwalter, ncoghlan, ryan.freckleton |
2009-02-05 11:59:37 | paul.moore | set | messageid: <1233835177.48.0.886593944329.issue5135@psf.upfronthosting.co.za> |
2009-02-05 11:59:36 | paul.moore | link | issue5135 messages |
2009-02-05 11:59:34 | paul.moore | create | |
|