Skip to content

Commit a2ce085

Browse files
committed
[hotfix] fix creation of dict from dict and kwargs, when storage is unmodifiable (of the src dict)
PullRequest: graalpython-open/39
2 parents cd641e7 + 495ee32 commit a2ce085

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_dict.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,7 @@ def test_create_seq_and_kw():
285285
d = dict({'a': 1, 'b': 2, 'c': 3}, d=4)
286286
for k in ['a', 'b', 'c', 'd']:
287287
assert k in d
288+
289+
d = dict(dict(a=1, b=2, c=3), d=4)
290+
for k in ['a', 'b', 'c', 'd']:
291+
assert k in d

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ public void doPDict(PDict self, PDict iterable, @SuppressWarnings("unused") PKey
300300
self.setDictStorage(iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE));
301301
}
302302

303+
@Specialization(guards = {"!isNoValue(iterable)", "!isEmpty(kwargs)"}, rewriteOn = HashingStorage.UnmodifiableStorageException.class)
304+
public void doPDictKwargs(PDict self, PDict iterable, PKeyword[] kwargs,
305+
@Cached("create()") UnionNode unionNode) {
306+
HashingStorage dictStorage = unionNode.execute(iterable.getDictStorage(), new KeywordsStorage(kwargs));
307+
self.setDictStorage(dictStorage);
308+
}
309+
303310
@Specialization(guards = {"!isNoValue(iterable)", "!isEmpty(kwargs)"})
304311
public void doPDictKwargs(PDict self, PDict iterable, PKeyword[] kwargs) {
305312
HashingStorage dictStorage = iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE);

0 commit comments

Comments
 (0)