[Python-Dev] deleting setdefaultencoding iin site.py is evil
Chris Withers
chris at simplistix.co.uk
Thu Aug 27 10:01:33 CEST 2009
Martin v. Löwis wrote:
>> - If people were somehow relying on sys not having an attribute called
>> _setdefaultencoding, or were relying on stuffing an attribute into sys
>> called _setdefaultencoding then... well... that seems pretty unlikely ;-)
>
> If people were using the reload trickery, that would break if the
> function changed its name.
No it doesn't:
$ svn diff
Index: Lib/site.py
===================================================================
--- Lib/site.py (revision 74552)
+++ Lib/site.py (working copy)
@@ -540,6 +540,7 @@
if hasattr(sys, "setdefaultencoding"):
+ sys._setdefaultencoding = sys.setdefaultencoding
del sys.setdefaultencoding
>>> import sys
>>> sys._setdefaultencoding
<built-in function setdefaultencoding>
>>> sys.setdefaultencoding
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setdefaultencoding'
>>> reload(sys)
<module 'sys' (built-in)>
>>> sys.setdefaultencoding
<built-in function setdefaultencoding>
>>> sys._setdefaultencoding
<built-in function setdefaultencoding>
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
More information about the Python-Dev
mailing list