@@ -2,25 +2,91 @@ pub(crate) use _contextvars::make_module;
2
2
3
3
#[ pymodule]
4
4
mod _contextvars {
5
+ use rustpython_vm:: builtins:: { PyStrRef , PyTypeRef } ;
6
+ use rustpython_vm:: function:: OptionalArg ;
7
+ use rustpython_vm:: { PyObjectRef , PyRef , PyResult , PyValue , VirtualMachine } ;
8
+
5
9
#[ pyattr]
6
- #[ pyclass( name = "Context" ) ]
7
- #[ derive( Debug , Default ) ]
10
+ #[ pyclass( name) ]
11
+ #[ derive( Debug , PyValue ) ]
8
12
struct Context { }
9
-
13
+
10
14
#[ pyimpl]
11
15
impl Context { }
12
-
16
+
13
17
#[ pyattr]
14
- #[ pyclass( name = "ContextVar" ) ]
15
- #[ derive( Debug , Default ) ]
16
- struct ContextVar { }
18
+ #[ pyclass( name) ]
19
+ #[ derive( Debug , PyValue ) ]
20
+ struct ContextVar {
21
+ #[ allow( dead_code) ] // TODO: RUSTPYTHON
22
+ name : String ,
23
+ #[ allow( dead_code) ] // TODO: RUSTPYTHON
24
+ default : Option < PyObjectRef > ,
25
+ }
26
+
27
+ #[ derive( FromArgs ) ]
28
+ struct ContextVarOptions {
29
+ #[ pyarg( positional) ]
30
+ name : PyStrRef ,
31
+ #[ pyarg( any, optional) ]
32
+ default : OptionalArg < PyObjectRef > ,
33
+ }
17
34
18
35
#[ pyimpl]
19
- impl ContextVar { }
36
+ impl ContextVar {
37
+ #[ pymethod( magic) ]
38
+ fn init ( & self , _args : ContextVarOptions , _vm : & VirtualMachine ) -> PyResult < ( ) > {
39
+ unimplemented ! ( "ContextVar.__init__() is currently under construction" )
40
+ }
41
+
42
+ #[ pyproperty]
43
+ fn name ( & self ) -> String {
44
+ self . name . clone ( )
45
+ }
46
+
47
+ #[ pymethod]
48
+ fn get (
49
+ & self ,
50
+ _default : OptionalArg < PyObjectRef > ,
51
+ _vm : & VirtualMachine ,
52
+ ) -> PyResult < PyObjectRef > {
53
+ unimplemented ! ( "ContextVar.get() is currently under construction" )
54
+ }
55
+
56
+ #[ pymethod]
57
+ fn set ( & self , _value : PyObjectRef , _vm : & VirtualMachine ) -> PyResult < ( ) > {
58
+ unimplemented ! ( "ContextVar.set() is currently under construction" )
59
+ }
60
+
61
+ #[ pymethod]
62
+ fn reset (
63
+ _zelf : PyRef < Self > ,
64
+ _token : PyRef < ContextToken > ,
65
+ _vm : & VirtualMachine ,
66
+ ) -> PyResult < ( ) > {
67
+ unimplemented ! ( "ContextVar.reset() is currently under construction" )
68
+ }
69
+
70
+ #[ pyclassmethod( magic) ]
71
+ fn class_getitem ( _cls : PyTypeRef , _key : PyStrRef , _vm : & VirtualMachine ) -> PyResult < ( ) > {
72
+ unimplemented ! ( "ContextVar.__class_getitem__() is currently under construction" )
73
+ }
74
+
75
+ #[ pymethod( magic) ]
76
+ fn repr ( _zelf : PyRef < Self > , _vm : & VirtualMachine ) -> String {
77
+ unimplemented ! ( "<ContextVar name={{}} default={{}} at {{}}" )
78
+ // format!(
79
+ // "<ContextVar name={} default={:?} at {:#x}>",
80
+ // zelf.name.as_str(),
81
+ // zelf.default.map_or("", |x| PyStr::from(*x).as_str()),
82
+ // zelf.get_id()
83
+ // )
84
+ }
85
+ }
20
86
21
87
#[ pyattr]
22
88
#[ pyclass( name = "Token" ) ]
23
- #[ derive( Debug , Default ) ]
89
+ #[ derive( Debug , PyValue ) ]
24
90
struct ContextToken { }
25
91
26
92
#[ pyimpl]
0 commit comments