Commit 7e3541d9 authored by Jason Madden's avatar Jason Madden

Merge branch 'zodb-on-pypy-support' of...

Merge branch 'zodb-on-pypy-support' of https://github.com/NextThought/persistent into zodb-on-pypy-support
parents f0ac08a6 f349051a
......@@ -332,7 +332,15 @@ class Persistent(object):
raise TypeError('No instance dict')
idict.clear()
for k, v in inst_dict.items():
idict[intern(k)] = v
# Normally the keys for instance attributes are interned.
# Do that here, but only if it is possible to do so.
# TODO: On Python 2 codebases that straddle Python3,
# and use 'from __future__ import unicode_literals' it's not
# unheard of to have unicode objects in the __dict__ by accident.
# Should we watch for that and attempt to encode it so it can be
# interned?
idict[intern(k) if type(k) is str else k] = v
slotnames = self._slotnames()
if slotnames:
for k, v in slots.items():
......
......@@ -966,6 +966,19 @@ class _Persistent_Base(object):
key2 = list(inst2.__dict__.keys())[0]
self.assertTrue(key1 is key2)
def test___setstate___doesnt_fail_on_non_string_keys(self):
class Derived(self._getTargetClass()):
pass
inst1 = Derived()
inst1.__setstate__({1: 2})
self.assertTrue(1 in inst1.__dict__)
class MyStr(str):
pass
mystr = MyStr('mystr')
inst1.__setstate__({mystr: 2})
self.assertTrue(mystr in inst1.__dict__)
def test___reduce__(self):
from persistent._compat import copy_reg
inst = self._makeOne()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment