Skip to content

Commit 0283c24

Browse files
authored
Merge pull request #3040 from HypothesisWorks/create-pull-request/patch
2 parents a17a6d9 + d5ec1d3 commit 0283c24

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch fixes :func:`~hypothesis.strategies.from_type` and
4+
:func:`~hypothesis.strategies.register_type_strategy` for
5+
:obj:`python:typing.NewType` on Python 3.10, which changed the
6+
underlying implementation (see :bpo:`44353` for details).

hypothesis-python/src/hypothesis/_settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,14 @@ def all(cls) -> List["HealthCheck"]:
461461
return list(HealthCheck)
462462

463463
data_too_large = 1
464-
"""Check for when the typical size of the examples you are generating
465-
exceeds the maximum allowed size too often."""
464+
"""Checks if too many examples are aborted for being too large.
465+
466+
This is measured by the number of random choices that Hypothesis makes
467+
in order to generate something, not the size of the generated object.
468+
For example, choosing a 100MB object from a predefined list would take
469+
only a few bits, while generating 10KB of JSON from scratch might trigger
470+
this health check.
471+
"""
466472

467473
filter_too_much = 2
468474
"""Check for when the test is filtering out too many examples, either

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ def register_type_strategy(
17111711
from hypothesis.strategies._internal import types
17121712

17131713
if not types.is_a_type(custom_type):
1714-
raise InvalidArgument("custom_type=%r must be a type")
1714+
raise InvalidArgument(f"custom_type={custom_type!r} must be a type")
17151715
elif not (isinstance(strategy, SearchStrategy) or callable(strategy)):
17161716
raise InvalidArgument(
17171717
"strategy=%r must be a SearchStrategy, or a function that takes "

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ def try_issubclass(thing, superclass):
9898

9999

100100
def is_a_new_type(thing):
101-
# At runtime, `typing.NewType` returns an identity function rather
102-
# than an actual type, but we can check whether that thing matches.
103-
return (
104-
hasattr(thing, "__supertype__")
105-
and getattr(thing, "__module__", None) in ("typing", "typing_extensions")
106-
and inspect.isfunction(thing)
107-
)
101+
if sys.version_info[:2] < (3, 10):
102+
# At runtime, `typing.NewType` returns an identity function rather
103+
# than an actual type, but we can check whether that thing matches.
104+
return (
105+
hasattr(thing, "__supertype__")
106+
and getattr(thing, "__module__", None) in ("typing", "typing_extensions")
107+
and inspect.isfunction(thing)
108+
)
109+
# In 3.10 and later, NewType is actually a class - which simplifies things.
110+
# See https://bugs.python.org/issue44353 for links to the various patches.
111+
return isinstance(thing, typing.NewType) # pragma: no cover # on 3.8, anyway
108112

109113

110114
def is_a_type(thing):

requirements/coverage.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ coverage==5.5
1010
# via -r requirements/coverage.in
1111
lark-parser==0.11.3
1212
# via -r requirements/coverage.in
13-
numpy==1.21.0
13+
numpy==1.21.1
1414
# via
1515
# -r requirements/coverage.in
1616
# pandas

requirements/tools.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ packaging==21.0
155155
# tox
156156
parso==0.8.2
157157
# via jedi
158-
pathspec==0.8.1
158+
pathspec==0.9.0
159159
# via black
160160
pbr==5.6.0
161161
# via stevedore
162-
pep517==0.10.0
162+
pep517==0.11.0
163163
# via pip-tools
164164
pexpect==4.8.0
165165
# via ipython
@@ -215,7 +215,7 @@ pytz==2021.1
215215
# via
216216
# babel
217217
# django
218-
pyupgrade==2.21.2
218+
pyupgrade==2.22.0
219219
# via shed
220220
pyyaml==5.4.1
221221
# via
@@ -290,11 +290,12 @@ toml==0.10.2
290290
# via
291291
# -r requirements/tools.in
292292
# mypy
293-
# pep517
294293
# pytest
295294
# tox
296-
tomli==1.0.4
297-
# via black
295+
tomli==1.1.0
296+
# via
297+
# black
298+
# pep517
298299
tox==3.24.0
299300
# via -r requirements/tools.in
300301
tqdm==4.61.2
@@ -303,7 +304,7 @@ traitlets==4.3.3
303304
# via
304305
# -r requirements/tools.in
305306
# ipython
306-
twine==3.4.1
307+
twine==3.4.2
307308
# via -r requirements/tools.in
308309
types-click==7.1.2
309310
# via -r requirements/tools.in

0 commit comments

Comments
 (0)