mirror of
https://github.com/python/cpython.git
synced 2025-10-12 01:43:12 +00:00
Only try to intern str objects when unpickling attributes.
This matches the behaviour implmented in _pickle.
This commit is contained in:
parent
f70b129d7c
commit
ebfecfde8b
1 changed files with 6 additions and 8 deletions
|
@ -1195,15 +1195,13 @@ class _Unpickler:
|
||||||
if isinstance(state, tuple) and len(state) == 2:
|
if isinstance(state, tuple) and len(state) == 2:
|
||||||
state, slotstate = state
|
state, slotstate = state
|
||||||
if state:
|
if state:
|
||||||
d = inst.__dict__
|
inst_dict = inst.__dict__
|
||||||
intern = sys.intern
|
intern = sys.intern
|
||||||
try:
|
for k, v in state.items():
|
||||||
for k, v in state.items():
|
if type(k) is str:
|
||||||
d[intern(k)] = v
|
inst_dict[intern(k)] = v
|
||||||
# keys in state don't have to be strings
|
else:
|
||||||
# don't blow up, but don't go out of our way
|
inst_dict[k] = v
|
||||||
except TypeError:
|
|
||||||
d.update(state)
|
|
||||||
if slotstate:
|
if slotstate:
|
||||||
for k, v in slotstate.items():
|
for k, v in slotstate.items():
|
||||||
setattr(inst, k, v)
|
setattr(inst, k, v)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue