Carsten Haese
2006-11-27 19:41:24 UTC
And is there a mechanism in Python that will allow me to override
the operators of a class, for all its occurrences, even the ones
implemented on C built-in objects?
No.the operators of a class, for all its occurrences, even the ones
implemented on C built-in objects?
this is
something that I think needs to change. All this talk about new-style
classes and class-type unification is empty words if you can't override
anything on any type without having to know whether it's written in C or
Python.
Duncan's "No" response was not referring to overriding in general, itsomething that I think needs to change. All this talk about new-style
classes and class-type unification is empty words if you can't override
anything on any type without having to know whether it's written in C or
Python.
was referring to the OP's original question which amounted to "Can I
affect the behavior of method Z by overriding methods X and Y".
The inability to influence a method by overriding completely different
methods has nothing to do with whether that method is implemented in C
or Python; it has to with whether the method in question calls the
overridden methods, and in general it won't.
You can change the behavior of a list's sort method by overriding sort.
You can't change the behavior of sort by overriding __getitem__ and
__setitem__, because sort does not call __getitem__ or __setitem__.
Hope this helps,
Carsten.