* Lie Ryan:
On 01/28/10 20:12, Alf P. Steinbach wrote:
>>> import builtins
>>>
>>> org_print = print
>>> builtins.print = 666
>>>
>>> print( "trallala" )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> org_print( "but is that really so smart?" )
but is that really so smart?
>>> _
Monkey patching follows (or should follow) the same rule as class
inheritance overriding: the overrider's input domain must be a superset
of the overriden's input domain and the overrider's output range must be
a subset of the overriden's output range. 666 object (int) is not even
remotely compatible with function object.
Yes, that's my point.
A 'print' replacement should ideally provide all the guarantees on behavior that
standard 'print' does.
And with that it's not so easy to put in a /correct/ replacement of 'print'; in
particular, it has to honor the 'file' keyword argument.
Thus the 3.x design makes it easy to replace 'print' incorrectly.
I'd rather still had 'print' as keyword... ;-)
Cheers,
- Alf
--
http://mail.python.org/mailman/listinfo/python-list