Commit db780d0d authored by Benjamin Peterson's avatar Benjamin Peterson

fix instance dicts with str subclasses (#13903)

parent 53b97712
...@@ -879,6 +879,16 @@ class DictTest(unittest.TestCase): ...@@ -879,6 +879,16 @@ class DictTest(unittest.TestCase):
values = list(it) + [drop] values = list(it) + [drop]
self.assertEqual(sorted(values), sorted(list(data.values()))) self.assertEqual(sorted(values), sorted(list(data.values())))
def test_instance_dict_getattr_str_subclass(self):
class Foo:
def __init__(self, msg):
self.msg = msg
f = Foo('123')
class _str(str):
pass
self.assertEqual(f.msg, getattr(f, _str('msg')))
self.assertEqual(f.msg, f.__dict__[_str('msg')])
from test import mapping_tests from test import mapping_tests
class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol): class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol):
......
...@@ -641,7 +641,11 @@ lookdict_split(PyDictObject *mp, PyObject *key, ...@@ -641,7 +641,11 @@ lookdict_split(PyDictObject *mp, PyObject *key,
register PyDictKeyEntry *ep; register PyDictKeyEntry *ep;
if (!PyUnicode_CheckExact(key)) { if (!PyUnicode_CheckExact(key)) {
return lookdict(mp, key, hash, value_addr); ep = lookdict(mp, key, hash, value_addr);
/* lookdict expects a combined-table, so fix value_addr */
i = ep - ep0;
*value_addr = &mp->ma_values[i];
return ep;
} }
i = (size_t)hash & mask; i = (size_t)hash & mask;
ep = &ep0[i]; ep = &ep0[i];
......
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