]> granicus.if.org Git - python/commitdiff
Only try to intern str objects when unpickling attributes.
authorAlexandre Vassalotti <alexandre@peadrop.com>
Mon, 25 May 2009 18:50:33 +0000 (18:50 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Mon, 25 May 2009 18:50:33 +0000 (18:50 +0000)
This matches the behaviour implmented in _pickle.

Lib/pickle.py

index b94b3058cd7696d76ba2d94597ecbae08c4fda51..720c1a00e6ef5762340d9f66b799301ba34971ac 100644 (file)
@@ -1195,15 +1195,13 @@ class _Unpickler:
         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)