Skip to content
Merged
Show file tree
Hide file tree
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
fix context
  • Loading branch information
youknowone committed Jan 23, 2026
commit c5a88d066c91d9dbac240c712a346202b8f94eb4
6 changes: 0 additions & 6 deletions Lib/test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ def fun():

ctx.run(fun)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
def test_context_getset_1(self):
c = contextvars.ContextVar('c')
Expand Down Expand Up @@ -317,8 +315,6 @@ def test_context_getset_4(self):
with self.assertRaisesRegex(ValueError, 'different Context'):
c.reset(tok)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
def test_context_getset_5(self):
c = contextvars.ContextVar('c', default=42)
Expand All @@ -332,8 +328,6 @@ def fun():
contextvars.copy_context().run(fun)
self.assertEqual(c.get(), [])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_context_copy_1(self):
ctx1 = contextvars.Context()
c = contextvars.ContextVar('c', default=42)
Expand Down
10 changes: 7 additions & 3 deletions crates/stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ mod _contextvars {
}

#[pymethod]
fn copy(&self) -> Self {
fn copy(&self, vm: &VirtualMachine) -> Self {
// Deep copy the vars - clone the underlying Hamt data, not just the PyRef
let vars_copy = HamtObject {
hamt: RefCell::new(self.inner.vars.hamt.borrow().clone()),
};
Self {
inner: ContextInner {
idx: Cell::new(usize::MAX),
vars: self.inner.vars.clone(),
vars: vars_copy.into_ref(&vm.ctx),
entered: Cell::new(false),
},
}
Expand Down Expand Up @@ -630,7 +634,7 @@ mod _contextvars {

#[pyfunction]
fn copy_context(vm: &VirtualMachine) -> PyContext {
PyContext::current(vm).copy()
PyContext::current(vm).copy(vm)
}

// Set Token.MISSING attribute
Expand Down