@@ -5,8 +5,8 @@ mod _contextvars {
55 use crate :: vm:: {
66 builtins:: { PyFunction , PyStrRef , PyTypeRef } ,
77 function:: { ArgCallable , FuncArgs , OptionalArg } ,
8- types:: Initializer ,
9- PyObjectRef , PyPayload , PyRef , PyResult , VirtualMachine ,
8+ types:: { Initializer , Representable } ,
9+ Py , PyObjectRef , PyPayload , PyRef , PyResult , VirtualMachine ,
1010 } ;
1111
1212 #[ pyattr]
@@ -99,7 +99,7 @@ mod _contextvars {
9999 default : OptionalArg < PyObjectRef > ,
100100 }
101101
102- #[ pyclass( with( Initializer ) ) ]
102+ #[ pyclass( with( Initializer , Representable ) ) ]
103103 impl ContextVar {
104104 #[ pygetset]
105105 fn name ( & self ) -> String {
@@ -133,9 +133,19 @@ mod _contextvars {
133133 fn class_getitem ( _cls : PyTypeRef , _key : PyStrRef , _vm : & VirtualMachine ) -> PyResult < ( ) > {
134134 unimplemented ! ( "ContextVar.__class_getitem__() is currently under construction" )
135135 }
136+ }
136137
137- #[ pymethod( magic) ]
138- fn repr ( _zelf : PyRef < Self > , _vm : & VirtualMachine ) -> String {
138+ impl Initializer for ContextVar {
139+ type Args = ContextVarOptions ;
140+
141+ fn init ( _obj : PyRef < Self > , _args : Self :: Args , _vm : & VirtualMachine ) -> PyResult < ( ) > {
142+ unimplemented ! ( "ContextVar.__init__() is currently under construction" )
143+ }
144+ }
145+
146+ impl Representable for ContextVar {
147+ #[ inline]
148+ fn repr_str ( _zelf : & Py < Self > , _vm : & VirtualMachine ) -> PyResult < String > {
139149 unimplemented ! ( "<ContextVar name={{}} default={{}} at {{}}" )
140150 // format!(
141151 // "<ContextVar name={} default={:?} at {:#x}>",
@@ -146,14 +156,6 @@ mod _contextvars {
146156 }
147157 }
148158
149- impl Initializer for ContextVar {
150- type Args = ContextVarOptions ;
151-
152- fn init ( _obj : PyRef < Self > , _args : Self :: Args , _vm : & VirtualMachine ) -> PyResult < ( ) > {
153- unimplemented ! ( "ContextVar.__init__() is currently under construction" )
154- }
155- }
156-
157159 #[ pyattr]
158160 #[ pyclass( name = "Token" ) ]
159161 #[ derive( Debug , PyPayload ) ]
@@ -172,7 +174,7 @@ mod _contextvars {
172174 old_value : PyObjectRef ,
173175 }
174176
175- #[ pyclass( with( Initializer ) ) ]
177+ #[ pyclass( with( Initializer , Representable ) ) ]
176178 impl ContextToken {
177179 #[ pygetset]
178180 fn var ( & self , _vm : & VirtualMachine ) -> PyObjectRef {
@@ -183,11 +185,6 @@ mod _contextvars {
183185 fn old_value ( & self , _vm : & VirtualMachine ) -> PyObjectRef {
184186 unimplemented ! ( "Token.old_value() is currently under construction" )
185187 }
186-
187- #[ pymethod( magic) ]
188- fn repr ( _zelf : PyRef < Self > , _vm : & VirtualMachine ) -> String {
189- unimplemented ! ( "<Token {{}}var={{}} at {{}}>" )
190- }
191188 }
192189
193190 impl Initializer for ContextToken {
@@ -198,6 +195,13 @@ mod _contextvars {
198195 }
199196 }
200197
198+ impl Representable for ContextToken {
199+ #[ inline]
200+ fn repr_str ( _zelf : & Py < Self > , _vm : & VirtualMachine ) -> PyResult < String > {
201+ unimplemented ! ( "<Token {{}}var={{}} at {{}}>" )
202+ }
203+ }
204+
201205 #[ pyfunction]
202206 fn copy_context ( ) { }
203207}
0 commit comments