Skip to content

Commit

Permalink
Fix (un-share) contextvar default value
Browse files Browse the repository at this point in the history
  • Loading branch information
jobh committed Jul 10, 2023
1 parent aea7cdd commit e898a62
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions hypothesis-python/src/hypothesis/strategies/_internal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def _from_type_deferred(thing: Type[Ex]) -> SearchStrategy[Ex]:
)


_recurse_guard: ContextVar = ContextVar("recurse_guard", default=[])
_recurse_guard: ContextVar = ContextVar("recurse_guard")


def _from_type(thing: Type[Ex]) -> SearchStrategy[Ex]:
Expand All @@ -1069,7 +1069,12 @@ def as_strategy(strat_or_callable, thing, final=True):

def from_type_guarded(thing):
"""Returns the result of producer, or ... if recursion on thing is encountered"""
recurse_guard = _recurse_guard.get()
try:
recurse_guard = _recurse_guard.get()
except LookupError:
# We can't simply define the contextvar with default=[], as the
# default object would be shared across contexts
_recurse_guard.set(recurse_guard := [])
if thing in recurse_guard:
raise RewindRecursive(thing)
recurse_guard.append(thing)
Expand Down

0 comments on commit e898a62

Please sign in to comment.