Skip to content

Commit ad455e4

Browse files
committed
update for review
1 parent af5201d commit ad455e4

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
RELEASE_TYPE: patch
22

3-
This patch adds more type hints to our source code, including improving the typing of :func:`~hypothesis.strategies.characters`.
3+
This patch adds more type hints to internal Hypothesis code.

hypothesis-python/src/hypothesis/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

11-
from typing import Any, Literal
11+
from typing import Literal
1212

1313
from hypothesis.internal.compat import ExceptionGroup
1414

@@ -232,7 +232,7 @@ class Found(HypothesisException):
232232
class RewindRecursive(Exception):
233233
"""Signal that the type inference should be rewound due to recursive types. Internal use only."""
234234

235-
def __init__(self, target: Any) -> None:
235+
def __init__(self, target: object) -> None:
236236
self.target = target
237237

238238

hypothesis-python/src/hypothesis/extra/numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def arrays(
531531
lambda s: arrays(dtype, s, elements=elements, fill=fill, unique=unique)
532532
)
533533
# From here on, we're only dealing with values and it's relatively simple.
534-
dtype = np.dtype(dtype) # type: ignore[arg-type,assignment]
534+
dtype = np.dtype(dtype) # type: ignore[arg-type]
535535
assert isinstance(dtype, np.dtype) # help mypy out a bit...
536536
if elements is None or isinstance(elements, Mapping):
537537
if dtype.kind in ("m", "M") and "[" not in dtype.str:

hypothesis-python/src/hypothesis/internal/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ def get_type_hints(thing: object) -> dict[str, Any]:
206206
# We still use the same trick on Python 3, because Numpy values and other
207207
# custom __floor__ or __ceil__ methods may convert via floats.
208208
# See issue #1667, Numpy issue 9068.
209-
def floor(x: float) -> int:
209+
def floor(x):
210210
y = int(x)
211211
if y != x and x < 0:
212212
return y - 1
213213
return y
214214

215215

216-
def ceil(x: float) -> int:
216+
def ceil(x):
217217
y = int(x)
218218
if y != x and x > 0:
219219
return y + 1

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
Protocol,
3737
TypeVar,
3838
Union,
39+
cast,
3940
get_args,
4041
get_origin,
4142
overload,
@@ -64,6 +65,7 @@
6465
from hypothesis.internal.cathetus import cathetus
6566
from hypothesis.internal.charmap import (
6667
Categories,
68+
CategoryName,
6769
as_general_categories,
6870
categories as all_categories,
6971
)
@@ -566,13 +568,13 @@ def characters(
566568
codec: Optional[str] = None,
567569
min_codepoint: Optional[int] = None,
568570
max_codepoint: Optional[int] = None,
569-
categories: Optional[Categories] = None,
570-
exclude_categories: Optional[Categories] = None,
571+
categories: Optional[Collection[CategoryName]] = None,
572+
exclude_categories: Optional[Collection[CategoryName]] = None,
571573
exclude_characters: Optional[Collection[str]] = None,
572574
include_characters: Optional[Collection[str]] = None,
573575
# Note: these arguments are deprecated aliases for backwards compatibility
574-
blacklist_categories: Optional[Categories] = None,
575-
whitelist_categories: Optional[Categories] = None,
576+
blacklist_categories: Optional[Collection[CategoryName]] = None,
577+
whitelist_categories: Optional[Collection[CategoryName]] = None,
576578
blacklist_characters: Optional[Collection[str]] = None,
577579
whitelist_characters: Optional[Collection[str]] = None,
578580
) -> SearchStrategy[str]:
@@ -627,7 +629,7 @@ def characters(
627629
check_valid_size(min_codepoint, "min_codepoint")
628630
check_valid_size(max_codepoint, "max_codepoint")
629631
check_valid_interval(min_codepoint, max_codepoint, "min_codepoint", "max_codepoint")
630-
632+
categories = cast(Optional[Categories], categories)
631633
if categories is not None and exclude_categories is not None:
632634
raise InvalidArgument(
633635
f"Pass at most one of {categories=} and {exclude_categories=} - "

whole_repo_tests/test_mypy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ def test_stateful_target_params_mutually_exclusive(tmp_path, decorator):
338338
"target_args",
339339
[
340340
"target=b1",
341-
"targets=(b1,)",
342341
# FIXME: temporary workaround for mypy bug, see hypothesis/pull/4136
343342
pytest.param("targets=(b1,)", marks=pytest.mark.xfail(strict=False)),
344343
"targets=(b1, b2)",

0 commit comments

Comments
 (0)