Closed danielballan closed 4 years ago
I would like @tacaswell to be a required reviewer here because I don't think we have ever used NotImplemented
in our projects, and I have never used it personally, so I want a second opinion on whether this is overly clever.
Would it be simpler to not define the dispatched-to methods and watch for AttributeError
?
I think NotImplemented
is a language feature that probably should be used more than it is. An AttributeError
can mean "Um, what? Do you have the wrong object?" NotImplemented
means "Reasonable question! But you are barking up the wrong tree." It's more explicit. @tacaswell also pointed out (via DM) that the NotImplemented
involves less stack thrashing and allows child classes to "turn off" a parent class' implementation.
Added tests.
Currently,
DocumenterRouter
routes any Events it sees to theevent_page
method, packing them into EventPages along the way. This means that if someone subclassesDocumentRouter
and does something useful theevent_page
method, it will apply toevent
as well, automatically.However, the reverse does not work. If a subclass defines
event
but notevent_page
, any Events will be handled but EventPages will pass through quietly.This PR allows a
DocumentRouter
subclass to defineevent
orevent_page
and have the documents flow to the one that is defined, working in the same way that__add__
and__radd__
do in Python. As before, the subclass may define both if it wishes (potentially useful for performance optimizations) or neither.This PR needs careful tests.