Skip to content

Commit 4533eea

Browse files
committed
Fix typechecking in mappingproxy constructor
1 parent bc2f247 commit 4533eea

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_types.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*graalpython.lib-python.3.test.test_types.CoroutineTests.test_non_gen_values
2323
*graalpython.lib-python.3.test.test_types.CoroutineTests.test_wrapper_object
2424
*graalpython.lib-python.3.test.test_types.CoroutineTests.test_wrong_args
25+
*graalpython.lib-python.3.test.test_types.MappingProxyTests.test_constructor
2526
*graalpython.lib-python.3.test.test_types.MappingProxyTests.test_contains
2627
*graalpython.lib-python.3.test.test_types.MappingProxyTests.test_get
2728
*graalpython.lib-python.3.test.test_types.MappingProxyTests.test_iterators

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,7 +3059,7 @@ Object doMapping(Object klass, PHashingCollection obj,
30593059
return factory().createMappingproxy(klass, getStorage.execute(obj));
30603060
}
30613061

3062-
@Specialization(guards = {"isSequence(frame, obj, lib)", "!isBuiltinMapping(obj)"}, limit = "1")
3062+
@Specialization(guards = {"isMapping(frame, obj, lib)", "!isBuiltinMapping(obj)"}, limit = "1")
30633063
Object doMapping(VirtualFrame frame, Object klass, PythonObject obj,
30643064
@Cached("create()") HashingStorage.InitNode initNode,
30653065
@SuppressWarnings("unused") @CachedLibrary("obj") PythonObjectLibrary lib) {
@@ -3072,7 +3072,7 @@ Object doMissing(Object klass, PNone none) {
30723072
throw raise(TypeError, ErrorMessages.MISSING_D_REQUIRED_S_ARGUMENT_S_POS, "mappingproxy()", "mapping", 1);
30733073
}
30743074

3075-
@Specialization(guards = {"!isSequence(frame, obj, lib)", "!isNoValue(obj)"}, limit = "1")
3075+
@Specialization(guards = {"!isMapping(frame, obj, lib)", "!isNoValue(obj)"}, limit = "1")
30763076
Object doInvalid(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") Object klass, Object obj,
30773077
@SuppressWarnings("unused") @CachedLibrary("obj") PythonObjectLibrary lib) {
30783078
throw raise(TypeError, ErrorMessages.ARG_MUST_BE_S_NOT_P, "mappingproxy()", "mapping", obj);
@@ -3082,11 +3082,14 @@ protected static boolean isBuiltinMapping(Object o) {
30823082
return o instanceof PHashingCollection;
30833083
}
30843084

3085-
protected boolean isSequence(VirtualFrame frame, Object o, PythonObjectLibrary library) {
3085+
protected boolean isMapping(VirtualFrame frame, Object o, PythonObjectLibrary library) {
30863086
PythonContext context = getContextRef().get();
3087+
if (o instanceof PList || o instanceof PTuple) {
3088+
return false;
3089+
}
30873090
Object state = IndirectCallContext.enter(frame, context, this);
30883091
try {
3089-
return library.isSequence(o);
3092+
return library.isMapping(o);
30903093
} finally {
30913094
IndirectCallContext.exit(frame, context, state);
30923095
}

0 commit comments

Comments
 (0)