[Python-checkins] r72919 - python/branches/py3k/Lib/pickle.py

alexandre.vassalotti python-checkins at python.org
Mon May 25 20:50:33 CEST 2009


Author: alexandre.vassalotti
Date: Mon May 25 20:50:33 2009
New Revision: 72919

Log:
Only try to intern str objects when unpickling attributes.
This matches the behaviour implmented in _pickle.


Modified:
   python/branches/py3k/Lib/pickle.py

Modified: python/branches/py3k/Lib/pickle.py
==============================================================================
--- python/branches/py3k/Lib/pickle.py	(original)
+++ python/branches/py3k/Lib/pickle.py	Mon May 25 20:50:33 2009
@@ -1195,15 +1195,13 @@
         if isinstance(state, tuple) and len(state) == 2:
             state, slotstate = state
         if state:
-            d = inst.__dict__
+            inst_dict = inst.__dict__
             intern = sys.intern
-            try:
-                for k, v in state.items():
-                    d[intern(k)] = v
-            # keys in state don't have to be strings
-            # don't blow up, but don't go out of our way
-            except TypeError:
-                d.update(state)
+            for k, v in state.items():
+                if type(k) is str:
+                    inst_dict[intern(k)] = v
+                else:
+                    inst_dict[k] = v
         if slotstate:
             for k, v in slotstate.items():
                 setattr(inst, k, v)


More information about the Python-checkins mailing list