Skip to content

Commit c7e4a79

Browse files
committed
gh-142829: Add test for __hash__ re-entrancy in Context comparison
1 parent 4e7e015 commit c7e4a79

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_context.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,22 @@ def __eq__(self, other):
570570
ctx2.run(var.set, object())
571571
ctx1 == ctx2
572572

573+
def test_context_eq_reentrant_contextvar_set_in_hash(self):
574+
var = contextvars.ContextVar("v")
575+
ctx1 = contextvars.Context()
576+
ctx2 = contextvars.Context()
577+
578+
class ReentrantHash:
579+
def __hash__(self):
580+
ctx1.run(lambda: var.set(object()))
581+
return 0
582+
def __eq__(self, other):
583+
return isinstance(other, ReentrantHash)
584+
585+
ctx1.run(var.set, ReentrantHash())
586+
ctx2.run(var.set, ReentrantHash())
587+
ctx1 == ctx2
588+
573589

574590
# HAMT Tests
575591

0 commit comments

Comments
 (0)