@@ -40,6 +40,7 @@ use crate::obj::objmap;
4040use crate :: obj:: objmappingproxy;
4141use crate :: obj:: objmemory;
4242use crate :: obj:: objmodule:: { self , PyModule } ;
43+ use crate :: obj:: objnamespace:: { self , PyNamespace } ;
4344use crate :: obj:: objnone:: { self , PyNone , PyNoneRef } ;
4445use crate :: obj:: objobject;
4546use crate :: obj:: objproperty;
@@ -158,6 +159,7 @@ pub struct PyContext {
158159 pub property_type : PyClassRef ,
159160 pub readonly_property_type : PyClassRef ,
160161 pub module_type : PyClassRef ,
162+ pub namespace_type : PyClassRef ,
161163 pub bound_method_type : PyClassRef ,
162164 pub weakref_type : PyClassRef ,
163165 pub weakproxy_type : PyClassRef ,
@@ -250,6 +252,7 @@ impl PyContext {
250252
251253 let dict_type = create_type ( "dict" , & type_type, & object_type) ;
252254 let module_type = create_type ( "module" , & type_type, & object_type) ;
255+ let namespace_type = create_type ( "SimpleNamespace" , & type_type, & object_type) ;
253256 let classmethod_type = create_type ( "classmethod" , & type_type, & object_type) ;
254257 let staticmethod_type = create_type ( "staticmethod" , & type_type, & object_type) ;
255258 let function_type = create_type ( "function" , & type_type, & object_type) ;
@@ -366,6 +369,7 @@ impl PyContext {
366369 readonly_property_type,
367370 generator_type,
368371 module_type,
372+ namespace_type,
369373 bound_method_type,
370374 weakref_type,
371375 weakproxy_type,
@@ -407,6 +411,7 @@ impl PyContext {
407411 objweakproxy:: init ( & context) ;
408412 objnone:: init ( & context) ;
409413 objmodule:: init ( & context) ;
414+ objnamespace:: init ( & context) ;
410415 objmappingproxy:: init ( & context) ;
411416 exceptions:: init ( & context) ;
412417 context
@@ -464,6 +469,10 @@ impl PyContext {
464469 self . module_type . clone ( )
465470 }
466471
472+ pub fn namespace_type ( & self ) -> PyClassRef {
473+ self . namespace_type . clone ( )
474+ }
475+
467476 pub fn set_type ( & self ) -> PyClassRef {
468477 self . set_type . clone ( )
469478 }
@@ -658,6 +667,10 @@ impl PyContext {
658667 )
659668 }
660669
670+ pub fn new_namespace ( & self ) -> PyObjectRef {
671+ PyObject :: new ( PyNamespace , self . namespace_type ( ) , Some ( self . new_dict ( ) ) )
672+ }
673+
661674 pub fn new_rustfunc < F , T , R > ( & self , f : F ) -> PyObjectRef
662675 where
663676 F : IntoPyNativeFunc < T , R > ,
0 commit comments