Skip to content

Commit 06525a6

Browse files
committed
GR-9750L dict creation from dict and kwargs
1 parent 72a5764 commit 06525a6

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,6 @@ def test_in_dict_keys():
282282

283283

284284
def test_create_seq_and_kw():
285-
d = dict([('a', 1), ('b', 2), ('c', 3)], d=4)
285+
d = dict({'a': 1, 'b': 2, 'c': 3}, d=4)
286286
for k in ['a', 'b', 'c', 'd']:
287287
assert k in d

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,18 @@ protected boolean hasKeysAttribute(PythonObject o) {
295295
return lookupKeysAttributeNode.execute(o, KEYS) != PNone.NO_VALUE;
296296
}
297297

298-
@Specialization(guards = {"!isNoValue(iterable)"})
298+
@Specialization(guards = {"!isNoValue(iterable)", "isEmpty(kwargs)"})
299299
public void doPDict(PDict self, PDict iterable, @SuppressWarnings("unused") PKeyword[] kwargs) {
300300
self.setDictStorage(iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE));
301301
}
302302

303+
@Specialization(guards = {"!isNoValue(iterable)", "!isEmpty(kwargs)"})
304+
public void doPDictKwargs(PDict self, PDict iterable, PKeyword[] kwargs) {
305+
HashingStorage dictStorage = iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE);
306+
dictStorage.addAll(new KeywordsStorage(kwargs));
307+
self.setDictStorage(dictStorage);
308+
}
309+
303310
@Specialization(guards = {"!isNoValue(mapping)", "!isPDict(mapping)", "hasKeysAttribute(mapping)"})
304311
public void doMapping(PDict self, PythonObject mapping, @SuppressWarnings("unused") PKeyword[] kwargs,
305312
@Cached("create(KEYS)") LookupAndCallUnaryNode callKeysNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private HashingStorageNodes.InitNode getInitNode() {
9191

9292
@Specialization(guards = "args.length == 1")
9393
public Object doVarargs(PDict self, Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs) {
94-
getInitNode().execute(self, args[0], PKeyword.EMPTY_KEYWORDS);
94+
getInitNode().execute(self, args[0], kwargs);
9595
return PNone.NONE;
9696
}
9797

0 commit comments

Comments
 (0)