Skip to content

Commit 4946847

Browse files
committed
[GR-23213] Get most of test_defaultdict pass
PullRequest: graalpython/1118
2 parents 028e735 + e6ac34e commit 4946847

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_basic
2+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_callable_arg
3+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_copy
14
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_deep_copy
5+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_keyerror_without_factory
6+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_missing
27
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_pickling
8+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_print
9+
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_repr
310
*graalpython.lib-python.3.test.test_defaultdict.TestDefaultDict.test_shallow_copy

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public abstract static class ReprNode extends PythonUnaryBuiltinNode {
133133
Object reprMethod(VirtualFrame frame, PMethod self,
134134
@CachedLibrary("self.getSelf()") PythonObjectLibrary lib,
135135
@Cached("createGetAttributeNode()") GetAttributeNode getNameAttrNode,
136-
@Cached("create()") GetNameNode getTypeNameNode) {
136+
@Cached GetNameNode getTypeNameNode) {
137137
String typeName = getTypeNameNode.execute(lib.getLazyPythonClass(self.getSelf()));
138-
return strFormat("<built-in method %s of %s object at 0x%x>", getNameAttrNode.executeObject(frame, self.getFunction()), typeName, hashCode(self));
138+
return strFormat("<bound method %s of %s object at 0x%x>", getNameAttrNode.executeObject(frame, self.getFunction()), typeName, hashCode(self));
139139
}
140140

141141
@TruffleBoundary(allowInlining = true)
@@ -149,7 +149,7 @@ private static String strFormat(String fmt, Object... objects) {
149149
}
150150

151151
protected static GetAttributeNode createGetAttributeNode() {
152-
return GetAttributeNode.create(SpecialAttributeNames.__NAME__, null);
152+
return GetAttributeNode.create(SpecialAttributeNames.__QUALNAME__, null);
153153
}
154154
}
155155

graalpython/lib-graalpython/_collections.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,24 @@ def __next__(self):
645645

646646

647647
class defaultdict(dict):
648-
def __init__(self, default_factory, *args, **kwds):
648+
def __init__(self, default_factory=None, *args, **kwds):
649649
dict.__init__(self, *args, **kwds)
650-
self.default_factory = default_factory
650+
if (default_factory is None or callable(default_factory)):
651+
self.default_factory = default_factory
652+
else:
653+
raise TypeError("first argument must be callable or None")
651654

652655
def __missing__(self, key):
653656
if self.default_factory is None:
654-
raise KeyError((key,))
657+
raise KeyError(key)
655658
self[key] = value = self.default_factory()
656659
return value
657-
660+
658661
def __repr__(self):
659-
return "%s(%r, %s)" % (type(self).__name__, self.default_factory, dict.__repr__(self))
662+
return "%s(%r, %s)" % (type(self).__name__, self.default_factory, dict.__repr__(self))
663+
664+
def copy(self):
665+
cp = defaultdict(default_factory=self.default_factory)
666+
for k,v in self.items():
667+
cp[k] = v
668+
return cp

0 commit comments

Comments
 (0)