|
1 | | -use super::{PyType, PyTypeRef}; |
| 1 | +use super::{tuple::IntoPyTuple, PyTupleRef, PyType, PyTypeRef}; |
2 | 2 | use crate::{ |
3 | 3 | builtins::PyDict, |
4 | 4 | class::PyClassImpl, |
5 | 5 | function::{FuncArgs, PyComparisonValue}, |
6 | 6 | recursion::ReprGuard, |
7 | 7 | types::{Comparable, Constructor, Initializer, PyComparisonOp, Representable}, |
8 | | - AsObject, Context, Py, PyObject, PyPayload, PyRef, PyResult, VirtualMachine, |
| 8 | + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, |
9 | 9 | }; |
10 | 10 |
|
11 | 11 | /// A simple attribute-based namespace. |
12 | 12 | /// |
13 | 13 | /// SimpleNamespace(**kwargs) |
14 | | -#[pyclass(module = false, name = "SimpleNamespace")] |
| 14 | +#[pyclass(module = "types", name = "SimpleNamespace")] |
15 | 15 | #[derive(Debug)] |
16 | 16 | pub struct PyNamespace {} |
17 | 17 |
|
@@ -43,7 +43,19 @@ impl PyNamespace { |
43 | 43 | flags(BASETYPE, HAS_DICT), |
44 | 44 | with(Constructor, Initializer, Comparable, Representable) |
45 | 45 | )] |
46 | | -impl PyNamespace {} |
| 46 | +impl PyNamespace { |
| 47 | + #[pymethod(magic)] |
| 48 | + fn reduce(zelf: PyObjectRef, vm: &VirtualMachine) -> PyTupleRef { |
| 49 | + let dict = zelf.as_object().dict().unwrap(); |
| 50 | + let obj = zelf.as_object().to_owned(); |
| 51 | + let result: (PyObjectRef, PyObjectRef, PyObjectRef) = ( |
| 52 | + obj.class().to_owned().into(), |
| 53 | + vm.new_tuple(()).into(), |
| 54 | + dict.into(), |
| 55 | + ); |
| 56 | + result.into_pytuple(vm) |
| 57 | + } |
| 58 | +} |
47 | 59 |
|
48 | 60 | impl Initializer for PyNamespace { |
49 | 61 | type Args = FuncArgs; |
|
0 commit comments