Skip to content

Commit affb5b8

Browse files
authored
Merge pull request #3961 from qthequartermasterman/add-types-to-engine
Add type annotations to `hypothesis/internal/conjecture/engine.py`
2 parents 88c80f7 + 8b28c80 commit affb5b8

File tree

9 files changed

+309
-131
lines changed

9 files changed

+309
-131
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ their individual contributions.
2121
* `Alex Willmer <https://github.com/moreati>`_ ([email protected])
2222
* `Andrea Pierré <https://www.github.com/kir0ul>`_
2323
* `Andrea Reina <https://www.github.com/andreareina>`_
24+
* `Andrew Sansom <https://www.github.com/qthequartermasterman>`_
2425
* `Anne Archibald <https://www.github.com/td-anne>`_
2526
* `Ben Anhalt <https://github.com/benanhalt>`_
2627
* `Ben Peterson <https://github.com/killthrush>`_ ([email protected])

hypothesis-python/RELEASE.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch adds some internal type annotations (:issue:`3074`).
4+
Thanks to Andrew Sansom for his contribution!

hypothesis-python/src/hypothesis/extra/pandas/impl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ def data_frames(
534534
def rows_only(draw):
535535
index = draw(index_strategy)
536536

537-
@check_function
538537
def row():
539538
result = draw(rows)
540539
check_type(abc.Iterable, result, "draw(row)")

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sysconfig
1818
import typing
1919
from functools import partial
20-
from typing import Any, ForwardRef, List, Optional, get_args
20+
from typing import Any, ForwardRef, List, Optional, TypedDict as TypedDict, get_args
2121

2222
try:
2323
BaseExceptionGroup = BaseExceptionGroup
@@ -28,18 +28,52 @@
2828
ExceptionGroup as ExceptionGroup,
2929
)
3030
if typing.TYPE_CHECKING: # pragma: no cover
31-
from typing_extensions import Concatenate as Concatenate, ParamSpec as ParamSpec
31+
from typing_extensions import (
32+
Concatenate as Concatenate,
33+
NotRequired as NotRequired,
34+
ParamSpec as ParamSpec,
35+
TypeAlias as TypeAlias,
36+
TypedDict as TypedDict,
37+
override as override,
38+
)
3239
else:
40+
# In order to use NotRequired, we need the version of TypedDict included in Python 3.11+.
41+
if sys.version_info[:2] >= (3, 11):
42+
from typing import NotRequired as NotRequired, TypedDict as TypedDict
43+
else:
44+
try:
45+
from typing_extensions import (
46+
NotRequired as NotRequired,
47+
TypedDict as TypedDict,
48+
)
49+
except ImportError:
50+
# We can use the old TypedDict from Python 3.8+ at runtime.
51+
class NotRequired:
52+
"""A runtime placeholder for the NotRequired type, which is not available in Python <3.11."""
53+
54+
def __class_getitem__(cls, item):
55+
return cls
56+
3357
try:
34-
from typing import Concatenate as Concatenate, ParamSpec as ParamSpec
58+
from typing import (
59+
Concatenate as Concatenate,
60+
ParamSpec as ParamSpec,
61+
TypeAlias as TypeAlias,
62+
override as override,
63+
)
3564
except ImportError:
3665
try:
3766
from typing_extensions import (
3867
Concatenate as Concatenate,
3968
ParamSpec as ParamSpec,
69+
TypeAlias as TypeAlias,
70+
override as override,
4071
)
4172
except ImportError:
4273
Concatenate, ParamSpec = None, None
74+
TypeAlias = None
75+
override = lambda f: f
76+
4377

4478
PYPY = platform.python_implementation() == "PyPy"
4579
GRAALPY = platform.python_implementation() == "GraalVM"

hypothesis-python/src/hypothesis/internal/conjecture/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def wrapper(tp):
9898
InterestingOrigin = Tuple[
9999
Type[BaseException], str, int, Tuple[Any, ...], Tuple[Tuple[Any, ...], ...]
100100
]
101-
TargetObservations = Dict[Optional[str], Union[int, float]]
101+
TargetObservations = Dict[str, Union[int, float]]
102102

103103
T = TypeVar("T")
104104

0 commit comments

Comments
 (0)