Skip to content
Merged
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
gh-142829: Add test for __hash__ re-entrancy in Context comparison
  • Loading branch information
abdoulrasheed committed Dec 20, 2025
commit c7e4a790ab722f52a29e1371e0c03abc49f90268
16 changes: 16 additions & 0 deletions Lib/test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,22 @@ def __eq__(self, other):
ctx2.run(var.set, object())
ctx1 == ctx2

def test_context_eq_reentrant_contextvar_set_in_hash(self):
var = contextvars.ContextVar("v")
ctx1 = contextvars.Context()
ctx2 = contextvars.Context()

class ReentrantHash:
def __hash__(self):
ctx1.run(lambda: var.set(object()))
return 0
def __eq__(self, other):
return isinstance(other, ReentrantHash)

ctx1.run(var.set, ReentrantHash())
ctx2.run(var.set, ReentrantHash())
ctx1 == ctx2


# HAMT Tests

Expand Down
Loading