Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.13] gh-143189: fix insertdict() for non-Unicode key (GH-143285)#143772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugovk merged 1 commit intopython:3.13frommethane:backport-43c7658-3.13
Jan 13, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletionsLib/test/test_dict.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1655,6 +1655,7 @@ def make_pairs():
self.assertGreaterEqual(eq_count, 1)

def test_clear_at_lookup(self):
# gh-140551 dict crash if clear is called at lookup stage
class X:
def __hash__(self):
return 1
Expand All@@ -1675,13 +1676,31 @@ def __eq__(self, other):
self.assertEqual(len(d), 1)

def test_split_table_update_with_str_subclass(self):
# gh-142218: inserting into a split table dictionary with a non str
# key that matches an existing key.
class MyStr(str): pass
class MyClass: pass
obj = MyClass()
obj.attr = 1
obj.__dict__[MyStr('attr')] = 2
self.assertEqual(obj.attr, 2)

def test_split_table_insert_with_str_subclass(self):
# gh-143189: inserting into split table dictionary with a non str
# key that matches an existing key in the shared table but not in
# the dict yet.

class MyStr(str): pass
class MyClass: pass

obj = MyClass()
obj.attr1 = 1

obj2 = MyClass()
d = obj2.__dict__
d[MyStr("attr1")] = 2
self.assertIsInstance(list(d)[0], MyStr)


class CAPITest(unittest.TestCase):

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fix crash when inserting a non-:class:`str` key into a split table
dictionary when the key matches an existing key in the split table
but has no corresponding value in the dict.
7 changes: 5 additions & 2 deletionsObjects/dictobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1832,7 +1832,7 @@ static int
insertdict(PyInterpreterState *interp, PyDictObject *mp,
PyObject *key, Py_hash_t hash, PyObject *value)
{
PyObject *old_value;
PyObject *old_value = NULL;
Py_ssize_t ix;

ASSERT_DICT_LOCKED(mp);
Expand All@@ -1856,11 +1856,14 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,

}

if (ix ==DKIX_EMPTY) {
if (old_value ==NULL) {
// insert_combined_dict() will convert from non DICT_KEYS_GENERAL table
// into DICT_KEYS_GENERAL table if key is not Unicode.
// We don't convert it before _Py_dict_lookup because non-Unicode key
// may change generic table into Unicode table.
//
// NOTE: ix may not be DKIX_EMPTY because split table may have key
// without value.
if (insert_combined_dict(interp, mp, hash, key, value) < 0) {
goto Fail;
}
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp