Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Draft methods and fields for ContextVar
Things are going to get worse before they get better.
  • Loading branch information
fanninpm committed Jan 30, 2022
commit bb8ba8b40a859d13258b568279f7f2f98a132382
80 changes: 73 additions & 7 deletions stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,91 @@ pub(crate) use _contextvars::make_module;

#[pymodule]
mod _contextvars {
use rustpython_vm::builtins::{PyStrRef, PyTypeRef};
use rustpython_vm::function::OptionalArg;
use rustpython_vm::{PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine};

#[pyattr]
#[pyclass(name = "Context")]
#[derive(Debug, Default)]
#[pyclass(name)]
#[derive(Debug, PyValue)]
struct Context {}

#[pyimpl]
impl Context {}

#[pyattr]
#[pyclass(name = "ContextVar")]
#[derive(Debug, Default)]
struct ContextVar {}
#[pyclass(name)]
#[derive(Debug, PyValue)]
struct ContextVar {
#[allow(dead_code)] // TODO: RUSTPYTHON
name: String,
#[allow(dead_code)] // TODO: RUSTPYTHON
default: Option<PyObjectRef>,
}

#[derive(FromArgs)]
struct ContextVarOptions {
#[pyarg(positional)]
name: PyStrRef,
#[pyarg(any, optional)]
default: OptionalArg<PyObjectRef>,
}

#[pyimpl]
impl ContextVar {}
impl ContextVar {
#[pymethod(magic)]
fn init(&self, _args: ContextVarOptions, _vm: &VirtualMachine) -> PyResult<()> {
unimplemented!("ContextVar.__init__() is currently under construction")
}

#[pyproperty]
fn name(&self) -> String {
self.name.clone()
}

#[pymethod]
fn get(
&self,
_default: OptionalArg<PyObjectRef>,
_vm: &VirtualMachine,
) -> PyResult<PyObjectRef> {
unimplemented!("ContextVar.get() is currently under construction")
}

#[pymethod]
fn set(&self, _value: PyObjectRef, _vm: &VirtualMachine) -> PyResult<()> {
unimplemented!("ContextVar.set() is currently under construction")
}

#[pymethod]
fn reset(
_zelf: PyRef<Self>,
_token: PyRef<ContextToken>,
_vm: &VirtualMachine,
) -> PyResult<()> {
unimplemented!("ContextVar.reset() is currently under construction")
}

#[pyclassmethod(magic)]
fn class_getitem(_cls: PyTypeRef, _key: PyStrRef, _vm: &VirtualMachine) -> PyResult<()> {
unimplemented!("ContextVar.__class_getitem__() is currently under construction")
}

#[pymethod(magic)]
fn repr(_zelf: PyRef<Self>, _vm: &VirtualMachine) -> String {
unimplemented!("<ContextVar name={{}} default={{}} at {{}}")
// format!(
// "<ContextVar name={} default={:?} at {:#x}>",
// zelf.name.as_str(),
// zelf.default.map_or("", |x| PyStr::from(*x).as_str()),
// zelf.get_id()
// )
}
}

#[pyattr]
#[pyclass(name = "Token")]
#[derive(Debug, Default)]
#[derive(Debug, PyValue)]
struct ContextToken {}

#[pyimpl]
Expand Down