Skip to content

Commit

Permalink
a few more imminent typings for hypofuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Feb 3, 2025
1 parent 4644a42 commit 24f9f0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
13 changes: 9 additions & 4 deletions hypothesis-python/src/hypothesis/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from collections import defaultdict
from collections.abc import Sequence
from contextlib import contextmanager
from typing import Any, NoReturn, Optional, Union
from typing import Any, Callable, NoReturn, Optional, Union
from weakref import WeakKeyDictionary

from hypothesis import Verbosity, settings
Expand Down Expand Up @@ -127,10 +127,15 @@ def deprecate_random_in_strategy(fmt, *args):


class BuildContext:
def __init__(self, data, *, is_final=False, close_on_capture=True):
assert isinstance(data, ConjectureData)
def __init__(
self,
data: ConjectureData,
*,
is_final: bool = False,
close_on_capture: bool = True,
) -> None:
self.data = data
self.tasks = []
self.tasks: list[Callable[[], Any]] = []
self.is_final = is_final
self.close_on_capture = close_on_capture
self.close_on_del = False
Expand Down
12 changes: 7 additions & 5 deletions hypothesis-python/src/hypothesis/internal/escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
from functools import partial
from inspect import getframeinfo
from pathlib import Path
from typing import NamedTuple, Optional
from types import ModuleType
from typing import Callable, NamedTuple, Optional

import hypothesis
from hypothesis.errors import _Trimmable
from hypothesis.internal.compat import BaseExceptionGroup
from hypothesis.utils.dynamicvariables import DynamicVariable


def belongs_to(package):
if not hasattr(package, "__file__"): # pragma: no cover
def belongs_to(package: ModuleType) -> Callable[[str], bool]:
if getattr(package, "__file__", None) is None: # pragma: no cover
return lambda filepath: False

assert package.__file__ is not None
root = Path(package.__file__).resolve().parent
cache = {str: {}, bytes: {}}
cache: dict[type, dict[str, bool]] = {str: {}, bytes: {}}

def accept(filepath):
def accept(filepath: str) -> bool:
ftype = type(filepath)
try:
return cache[ftype][filepath]
Expand Down

0 comments on commit 24f9f0a

Please sign in to comment.