Skip to content

Commit 9f385d9

Browse files
committed
some more misc typings
1 parent a07e950 commit 9f385d9

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

hypothesis-python/src/hypothesis/strategies/_internal/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
get_type_hints,
8080
is_typed_named_tuple,
8181
)
82+
from hypothesis.internal.conjecture.data import ConjectureData
8283
from hypothesis.internal.conjecture.utils import (
8384
calc_label_from_cls,
8485
check_sample,
@@ -2199,7 +2200,7 @@ class DataObject:
21992200
# Note that "only exists" here really means "is only exported to users",
22002201
# but we want to treat it as "semi-stable", not document it as "public API".
22012202

2202-
def __init__(self, data):
2203+
def __init__(self, data: ConjectureData) -> None:
22032204
self.count = 0
22042205
self.conjecture_data = data
22052206

hypothesis-python/src/hypothesis/strategies/_internal/numbers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from hypothesis.control import reject
1717
from hypothesis.errors import InvalidArgument
18+
from hypothesis.internal.conjecture.data import ConjectureData
1819
from hypothesis.internal.filtering import (
1920
get_float_predicate_bounds,
2021
get_integer_predicate_bounds,
@@ -64,7 +65,7 @@ def __repr__(self) -> str:
6465
return f"integers(max_value={self.end})"
6566
return f"integers({self.start}, {self.end})"
6667

67-
def do_draw(self, data):
68+
def do_draw(self, data: ConjectureData) -> int:
6869
# For bounded integers, make the bounds and near-bounds more likely.
6970
weights = None
7071
if (
@@ -141,7 +142,7 @@ def integers(
141142
return IntegersStrategy(min_value, max_value)
142143

143144

144-
class FloatStrategy(SearchStrategy):
145+
class FloatStrategy(SearchStrategy[float]):
145146
"""A strategy for floating point numbers."""
146147

147148
def __init__(
@@ -179,7 +180,7 @@ def __repr__(self) -> str:
179180
f"{self.allow_nan=}, {self.smallest_nonzero_magnitude=})"
180181
).replace("self.", "")
181182

182-
def do_draw(self, data):
183+
def do_draw(self, data: ConjectureData) -> float:
183184
return data.draw_float(
184185
min_value=self.min_value,
185186
max_value=self.max_value,
@@ -500,7 +501,7 @@ def floats(
500501

501502
if width < 64:
502503

503-
def downcast(x):
504+
def downcast(x: float) -> float:
504505
try:
505506
return float_of(x, width)
506507
except OverflowError: # pragma: no cover
@@ -510,10 +511,10 @@ def downcast(x):
510511
return result
511512

512513

513-
class NanStrategy(SearchStrategy):
514+
class NanStrategy(SearchStrategy[float]):
514515
"""Strategy for sampling the space of nan float values."""
515516

516-
def do_draw(self, data):
517+
def do_draw(self, data: ConjectureData) -> float:
517518
# Nans must have all exponent bits and the first mantissa bit set, so
518519
# we generate by taking 64 random bits and setting the required ones.
519520
sign_bit = int(data.draw_boolean()) << 63

hypothesis-python/src/hypothesis/strategies/_internal/strings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from hypothesis.errors import HypothesisWarning, InvalidArgument
1818
from hypothesis.internal import charmap
19+
from hypothesis.internal.conjecture.data import ConjectureData
1920
from hypothesis.internal.conjecture.providers import COLLECTION_DEFAULT_MAX_SIZE
2021
from hypothesis.internal.filtering import max_len, min_len
2122
from hypothesis.internal.intervalsets import IntervalSet
@@ -43,10 +44,12 @@ def _check_is_single_character(c):
4344
return c
4445

4546

46-
class OneCharStringStrategy(SearchStrategy):
47+
class OneCharStringStrategy(SearchStrategy[str]):
4748
"""A strategy which generates single character strings of text type."""
4849

49-
def __init__(self, intervals, force_repr=None):
50+
def __init__(
51+
self, intervals: IntervalSet, force_repr: Optional[str] = None
52+
) -> None:
5053
assert isinstance(intervals, IntervalSet)
5154
self.intervals = intervals
5255
self._force_repr = force_repr
@@ -119,7 +122,7 @@ def from_alphabet(cls, alphabet):
119122
def __repr__(self) -> str:
120123
return self._force_repr or f"OneCharStringStrategy({self.intervals!r})"
121124

122-
def do_draw(self, data):
125+
def do_draw(self, data: ConjectureData) -> str:
123126
return data.draw_string(self.intervals, min_size=1, max_size=1)
124127

125128

0 commit comments

Comments
 (0)