Skip to content

Commit

Permalink
more typing
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Feb 5, 2025
1 parent 7cb0989 commit db28d3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
TypeVar,
Union,
overload,
Iterable,
)
from unittest import TestCase

Expand Down Expand Up @@ -321,7 +322,7 @@ def accept(test):
return accept


def encode_failure(choices):
def encode_failure(choices: Iterable[ChoiceT]) -> bytes:
blob = choices_to_bytes(choices)
compressed = zlib.compress(blob)
if len(compressed) < len(blob):
Expand Down Expand Up @@ -687,7 +688,7 @@ def skip_exceptions_to_reraise():
return tuple(sorted(exceptions, key=str))


def failure_exceptions_to_catch():
def failure_exceptions_to_catch() -> tuple[type[BaseException], ...]:
"""Return a tuple of exceptions meaning 'this test has failed', to catch.
This is intended to cover most common test runners; if you would
Expand Down
9 changes: 6 additions & 3 deletions hypothesis-python/src/hypothesis/internal/escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from functools import partial
from inspect import getframeinfo
from pathlib import Path
from types import ModuleType
from types import ModuleType, TracebackType
from typing import Callable, NamedTuple, Optional

import hypothesis
Expand Down Expand Up @@ -57,7 +57,9 @@ def accept(filepath: str) -> bool:
is_hypothesis_file = belongs_to(hypothesis)


def get_trimmed_traceback(exception=None):
def get_trimmed_traceback(
exception: Optional[BaseException] = None,
) -> Optional[TracebackType]:
"""Return the current traceback, minus any frames added by Hypothesis."""
if exception is None:
_, exception, tb = sys.exc_info()
Expand All @@ -67,9 +69,10 @@ def get_trimmed_traceback(exception=None):
# was raised inside Hypothesis. Additionally, the environment variable
# HYPOTHESIS_NO_TRACEBACK_TRIM is respected if nonempty, because verbose
# mode is prohibitively slow when debugging strategy recursion errors.
assert hypothesis.settings.default is not None
if (
tb is None
or os.environ.get("HYPOTHESIS_NO_TRACEBACK_TRIM", None)
or os.environ.get("HYPOTHESIS_NO_TRACEBACK_TRIM")
or hypothesis.settings.default.verbosity >= hypothesis.Verbosity.debug
or (
is_hypothesis_file(traceback.extract_tb(tb)[-1][0])
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/internal/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _clean_source(src: str) -> bytes:
return "\n".join(x.rstrip() for x in src.splitlines() if x.rstrip()).encode()


def function_digest(function):
def function_digest(function: Any) -> bytes:
"""Returns a string that is stable across multiple invocations across
multiple processes and is prone to changing significantly in response to
minor changes to the function.
Expand Down

0 comments on commit db28d3a

Please sign in to comment.