MCPcopy Create free account
hub / github.com/MagicStack/contextvars / ctx1_fun

Method ctx1_fun

tests/test_basics.py:319–331  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

317 c = contextvars.ContextVar('c', default=42)
318
319 def ctx1_fun():
320 c.set(10)
321
322 ctx2 = ctx1.copy()
323 self.assertEqual(ctx2[c], 10)
324
325 c.set(20)
326 self.assertEqual(ctx1[c], 20)
327 self.assertEqual(ctx2[c], 10)
328
329 ctx2.run(ctx2_fun)
330 self.assertEqual(ctx1[c], 20)
331 self.assertEqual(ctx2[c], 30)
332
333 def ctx2_fun():
334 self.assertEqual(c.get(), 10)

Callers

nothing calls this directly

Calls 3

setMethod · 0.80
copyMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected