@@ -6,8 +6,8 @@ use crate::iterator;
6
6
use crate :: slots:: { AsMapping , Iterable , SlotConstructor } ;
7
7
use crate :: vm:: VirtualMachine ;
8
8
use crate :: {
9
- IntoPyObject , ItemProtocol , PyClassImpl , PyContext , PyObjectRef , PyRef , PyResult , PyValue ,
10
- TryFromObject , TypeProtocol ,
9
+ IdProtocol , IntoPyObject , ItemProtocol , PyClassImpl , PyContext , PyObjectRef , PyRef , PyResult ,
10
+ PyValue , TryFromObject , TypeProtocol ,
11
11
} ;
12
12
13
13
#[ pyclass( module = false , name = "mappingproxy" ) ]
@@ -40,10 +40,20 @@ impl SlotConstructor for PyMappingProxy {
40
40
type Args = PyObjectRef ;
41
41
42
42
fn py_new ( cls : PyTypeRef , mapping : Self :: Args , vm : & VirtualMachine ) -> PyResult {
43
- Self {
44
- mapping : MappingProxyInner :: Dict ( mapping) ,
43
+ if !PyMapping :: check ( cls, vm)
44
+ || cls. is ( & vm. ctx . types . list_type )
45
+ || cls. is ( & vm. ctx . types . tuple_type )
46
+ {
47
+ Err ( vm. new_type_error ( format ! (
48
+ "mappingproxy() argument must be a mapping, not {}" ,
49
+ cls
50
+ ) ) )
51
+ } else {
52
+ Self {
53
+ mapping : MappingProxyInner :: Dict ( mapping) ,
54
+ }
55
+ . into_pyresult_with_type ( vm, cls)
45
56
}
46
- . into_pyresult_with_type ( vm, cls)
47
57
}
48
58
}
49
59
0 commit comments