Skip to content

Commit e5bf72e

Browse files
committed
contextvars
1 parent 1f62190 commit e5bf72e

File tree

6 files changed

+549
-117
lines changed

6 files changed

+549
-117
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_context.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test.support import threading_helper
1111

1212
try:
13-
from _testcapi import hamt
13+
from _testinternalcapi import hamt
1414
except ImportError:
1515
hamt = None
1616

@@ -42,8 +42,6 @@ def test_context_var_new_1(self):
4242

4343
self.assertNotEqual(hash(c), hash('aaa'))
4444

45-
# TODO: RUSTPYTHON
46-
@unittest.expectedFailure
4745
@isolated_context
4846
def test_context_var_repr_1(self):
4947
c = contextvars.ContextVar('a')
@@ -101,8 +99,6 @@ def test_context_typerrors_1(self):
10199
with self.assertRaisesRegex(TypeError, 'ContextVar key was expected'):
102100
ctx.get(1)
103101

104-
# TODO: RUSTPYTHON
105-
@unittest.expectedFailure
106102
def test_context_get_context_1(self):
107103
ctx = contextvars.copy_context()
108104
self.assertIsInstance(ctx, contextvars.Context)
@@ -115,8 +111,6 @@ def test_context_run_1(self):
115111
with self.assertRaisesRegex(TypeError, 'missing 1 required'):
116112
ctx.run()
117113

118-
# TODO: RUSTPYTHON
119-
@unittest.expectedFailure
120114
def test_context_run_2(self):
121115
ctx = contextvars.Context()
122116

@@ -145,8 +139,6 @@ def func(*args, **kwargs):
145139
((11, 'bar'), {'spam': 'foo'}))
146140
self.assertEqual(a, {})
147141

148-
# TODO: RUSTPYTHON
149-
@unittest.expectedFailure
150142
def test_context_run_3(self):
151143
ctx = contextvars.Context()
152144

@@ -187,8 +179,6 @@ def func1():
187179
self.assertEqual(returned_ctx[var], 'spam')
188180
self.assertIn(var, returned_ctx)
189181

190-
# TODO: RUSTPYTHON
191-
@unittest.expectedFailure
192182
def test_context_run_5(self):
193183
ctx = contextvars.Context()
194184
var = contextvars.ContextVar('var')
@@ -203,8 +193,6 @@ def func():
203193

204194
self.assertIsNone(var.get(None))
205195

206-
# TODO: RUSTPYTHON
207-
@unittest.expectedFailure
208196
def test_context_run_6(self):
209197
ctx = contextvars.Context()
210198
c = contextvars.ContextVar('a', default=0)
@@ -219,8 +207,6 @@ def fun():
219207

220208
ctx.run(fun)
221209

222-
# TODO: RUSTPYTHON
223-
@unittest.expectedFailure
224210
def test_context_run_7(self):
225211
ctx = contextvars.Context()
226212

@@ -286,8 +272,6 @@ def test_context_getset_1(self):
286272
self.assertEqual(len(ctx2), 0)
287273
self.assertEqual(list(ctx2), [])
288274

289-
# TODO: RUSTPYTHON
290-
@unittest.expectedFailure
291275
@isolated_context
292276
def test_context_getset_2(self):
293277
v1 = contextvars.ContextVar('v1')
@@ -297,8 +281,6 @@ def test_context_getset_2(self):
297281
with self.assertRaisesRegex(ValueError, 'by a different'):
298282
v2.reset(t1)
299283

300-
# TODO: RUSTPYTHON
301-
@unittest.expectedFailure
302284
@isolated_context
303285
def test_context_getset_3(self):
304286
c = contextvars.ContextVar('c', default=42)
@@ -324,8 +306,6 @@ def fun():
324306

325307
ctx.run(fun)
326308

327-
# TODO: RUSTPYTHON
328-
@unittest.expectedFailure
329309
@isolated_context
330310
def test_context_getset_4(self):
331311
c = contextvars.ContextVar('c', default=42)
@@ -378,8 +358,6 @@ def ctx2_fun():
378358

379359
ctx1.run(ctx1_fun)
380360

381-
# TODO: RUSTPYTHON
382-
@unittest.expectedFailure
383361
@isolated_context
384362
@threading_helper.requires_working_threading()
385363
def test_context_threads_1(self):
@@ -470,7 +448,7 @@ class EqError(Exception):
470448
pass
471449

472450

473-
@unittest.skipIf(hamt is None, '_testcapi lacks "hamt()" function')
451+
@unittest.skipIf(hamt is None, '_testinternalcapi.hamt() not available')
474452
class HamtTest(unittest.TestCase):
475453

476454
def test_hashkey_helper_1(self):

common/src/hash.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ impl HashSecret {
8888
}
8989
}
9090

91+
#[inline]
92+
pub fn hash_pointer(value: usize) -> PyHash {
93+
// TODO: 32bit?
94+
let hash = (value >> 4) | value;
95+
hash as _
96+
}
97+
9198
#[inline]
9299
pub fn hash_float(value: f64) -> Option<PyHash> {
93100
// cpython _Py_HashDouble

stdlib/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cfg-if = { workspace = true }
2828
crossbeam-utils = { workspace = true }
2929
hex = { workspace = true }
3030
itertools = { workspace = true }
31+
indexmap = { workspace = true }
3132
libc = { workspace = true }
3233
nix = { workspace = true }
3334
num-complex = { workspace = true }
@@ -37,6 +38,7 @@ num-traits = { workspace = true }
3738
num_enum = { workspace = true }
3839
once_cell = { workspace = true }
3940
parking_lot = { workspace = true }
41+
thread_local = { workspace = true }
4042

4143
memchr = { workspace = true }
4244
base64 = "0.13.0"

0 commit comments

Comments
 (0)