Thanks to visit codestin.com
Credit goes to github.com

Skip to content

contextvars #5300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 2 additions & 24 deletions Lib/test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from test.support import threading_helper

try:
from _testcapi import hamt
from _testinternalcapi import hamt
except ImportError:
hamt = None

Expand Down Expand Up @@ -42,8 +42,6 @@ def test_context_var_new_1(self):

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

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
def test_context_var_repr_1(self):
c = contextvars.ContextVar('a')
Expand Down Expand Up @@ -101,8 +99,6 @@ def test_context_typerrors_1(self):
with self.assertRaisesRegex(TypeError, 'ContextVar key was expected'):
ctx.get(1)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_context_get_context_1(self):
ctx = contextvars.copy_context()
self.assertIsInstance(ctx, contextvars.Context)
Expand All @@ -115,8 +111,6 @@ def test_context_run_1(self):
with self.assertRaisesRegex(TypeError, 'missing 1 required'):
ctx.run()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_context_run_2(self):
ctx = contextvars.Context()

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

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_context_run_3(self):
ctx = contextvars.Context()

Expand Down Expand Up @@ -187,8 +179,6 @@ def func1():
self.assertEqual(returned_ctx[var], 'spam')
self.assertIn(var, returned_ctx)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_context_run_5(self):
ctx = contextvars.Context()
var = contextvars.ContextVar('var')
Expand All @@ -203,8 +193,6 @@ def func():

self.assertIsNone(var.get(None))

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

ctx.run(fun)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_context_run_7(self):
ctx = contextvars.Context()

Expand Down Expand Up @@ -286,8 +272,6 @@ def test_context_getset_1(self):
self.assertEqual(len(ctx2), 0)
self.assertEqual(list(ctx2), [])

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
def test_context_getset_2(self):
v1 = contextvars.ContextVar('v1')
Expand All @@ -297,8 +281,6 @@ def test_context_getset_2(self):
with self.assertRaisesRegex(ValueError, 'by a different'):
v2.reset(t1)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
def test_context_getset_3(self):
c = contextvars.ContextVar('c', default=42)
Expand All @@ -324,8 +306,6 @@ def fun():

ctx.run(fun)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
def test_context_getset_4(self):
c = contextvars.ContextVar('c', default=42)
Expand Down Expand Up @@ -378,8 +358,6 @@ def ctx2_fun():

ctx1.run(ctx1_fun)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@isolated_context
@threading_helper.requires_working_threading()
def test_context_threads_1(self):
Expand Down Expand Up @@ -470,7 +448,7 @@ class EqError(Exception):
pass


@unittest.skipIf(hamt is None, '_testcapi lacks "hamt()" function')
@unittest.skipIf(hamt is None, '_testinternalcapi.hamt() not available')
class HamtTest(unittest.TestCase):

def test_hashkey_helper_1(self):
Expand Down
7 changes: 7 additions & 0 deletions common/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ impl HashSecret {
}
}

#[inline]
pub fn hash_pointer(value: usize) -> PyHash {
// TODO: 32bit?
let hash = (value >> 4) | value;
hash as _
}

#[inline]
pub fn hash_float(value: f64) -> Option<PyHash> {
// cpython _Py_HashDouble
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cfg-if = { workspace = true }
crossbeam-utils = { workspace = true }
hex = { workspace = true }
itertools = { workspace = true }
indexmap = { workspace = true }
libc = { workspace = true }
nix = { workspace = true }
num-complex = { workspace = true }
Expand All @@ -37,6 +38,7 @@ num-traits = { workspace = true }
num_enum = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
thread_local = { workspace = true }

memchr = { workspace = true }
base64 = "0.13.0"
Expand Down
Loading