tried to do this for
#3802 late in 1.1 but it's too critical if someone is doing a while loop, and here's at least one example: https://github.com/albertov/py-mailing/blob/a81d71f35b3c04de75cca48eb82b0b85bbaaf915/mailing/models/util.py#L45. there's no reason that person would have done that besides copying our code. additionally, if we put
__clause_element__() onto ClauseElement, there's a lot of internal checks that should also be optimized.
other more far-out tricks would be:
return a copy of the object that raises some assertion on
__clause_element__(). though this is expensive
__clause_element__()and replace with some totally other method. But we'd need almost-forever backwards compat for calling upon
__clause_element__also in this case. It sort of suggests all the places where we do
hasattr(obj, '__clause_element__')should become some other kind of single call that perhaps we can put into cutils. Detecting
__clause_element__itself would then raise some kind of deprecation warning.