Skip to content

Commit

Permalink
Merge pull request #3471 from HypothesisWorks/create-pull-request/patch
Browse files Browse the repository at this point in the history
Update pinned dependencies
  • Loading branch information
Zac-HD committed Oct 2, 2022
2 parents 576a3c7 + 4c94bf4 commit 7839707
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -56,6 +56,7 @@ jobs:
- check-django41
- check-django40
- check-django32
- check-pandas15
- check-pandas14
- check-pandas13
- check-pandas12
Expand Down
5 changes: 5 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,5 @@
RELEASE_TYPE: minor

This release defines ``__bool__()`` on :class:`~hypothesis.strategies.SearchStrategy`.
It always returns ``True``, like before, but also emits a warning to help with
cases where you intended to draw a value (:issue:`3463`).
11 changes: 11 additions & 0 deletions hypothesis-python/docs/conf.py
Expand Up @@ -82,6 +82,17 @@ def setup(app):
# See https://sphinx-hoverxref.readthedocs.io/en/latest/configuration.html
hoverxref_auto_ref = True
hoverxref_domains = ["py"]
hoverxref_role_types = {
"attr": "tooltip",
"class": "tooltip",
"const": "tooltip",
"exc": "tooltip",
"func": "tooltip",
"meth": "tooltip",
"mod": "tooltip",
"obj": "tooltip",
"ref": "tooltip",
}

intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
Expand Down
13 changes: 13 additions & 0 deletions hypothesis-python/docs/details.rst
Expand Up @@ -420,6 +420,19 @@ there is a natural metric like "floating-point error", "load factor" or

.. autofunction:: hypothesis.target

.. code-block:: python
from hypothesis import given, strategies as st, target
@given(st.floats(0, 1e100), st.floats(0, 1e100), st.floats(0, 1e100))
def test_associativity_with_target(a, b, c):
ab_c = (a + b) + c
a_bc = a + (b + c)
difference = abs(ab_c - a_bc)
target(difference) # Without this, the test almost always passes
assert difference < 2.0
We recommend that users also skim the papers introducing targeted PBT;
from `ISSTA 2017 <http://proper.softlab.ntua.gr/papers/issta2017.pdf>`__
and `ICST 2018 <http://proper.softlab.ntua.gr/papers/icst2018.pdf>`__.
Expand Down
10 changes: 5 additions & 5 deletions hypothesis-python/docs/extras.rst
Expand Up @@ -28,12 +28,12 @@ There are separate pages for :doc:`django` and :doc:`numpy`.
.. automodule:: hypothesis.extra.dpcontracts
:members:

.. tip::
.. tip::

For new projects, we recommend using either :pypi:`deal` or :pypi:`icontract`
and :pypi:`icontract-hypothesis` over :pypi:`dpcontracts`.
They're generally more powerful tools for design-by-contract programming,
and have substantially nicer Hypothesis integration too!
For new projects, we recommend using either :pypi:`deal` or :pypi:`icontract`
and :pypi:`icontract-hypothesis` over :pypi:`dpcontracts`.
They're generally more powerful tools for design-by-contract programming,
and have substantially nicer Hypothesis integration too!

.. automodule:: hypothesis.extra.lark
:members:
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/docs/numpy.rst
Expand Up @@ -47,7 +47,7 @@ Supported versions
There is quite a lot of variation between pandas versions. We only
commit to supporting the latest version of pandas, but older minor versions are
supported on a "best effort" basis. Hypothesis is currently tested against
and confirmed working with every Pandas minor version from 1.0 through to 1.4.
and confirmed working with every Pandas minor version from 1.0 through to 1.5.

Releases that are not the latest patch release of their minor version are not
tested or officially supported, but will probably also work unless you hit a
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/setup.py
Expand Up @@ -66,7 +66,7 @@ def local_file(name):
# zoneinfo is an odd one: every dependency is conditional, because they're
# only necessary on old versions of Python or Windows systems.
"zoneinfo": [
"tzdata>=2022.2 ; sys_platform == 'win32'",
"tzdata>=2022.4 ; sys_platform == 'win32'",
"backports.zoneinfo>=0.2.1 ; python_version<'3.9'",
],
# We only support Django versions with upstream support - see
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/array_api.py
Expand Up @@ -163,7 +163,7 @@ def find_castable_builtin_for_dtype(


@check_function
def dtype_from_name(xp: Any, name: str) -> DataType:
def dtype_from_name(xp: Any, name: str) -> Any:
if name in DTYPE_NAMES:
try:
return getattr(xp, name)
Expand Down
Expand Up @@ -29,6 +29,7 @@
from hypothesis.control import _current_build_context, assume
from hypothesis.errors import (
HypothesisException,
HypothesisWarning,
InvalidArgument,
NonInteractiveExampleWarning,
UnsatisfiedAssumption,
Expand Down Expand Up @@ -396,6 +397,14 @@ def __or__(self, other: "SearchStrategy[T]") -> "SearchStrategy[Union[Ex, T]]":
raise ValueError(f"Cannot | a SearchStrategy with {other!r}")
return OneOfStrategy((self, other))

def __bool__(self) -> bool:
warnings.warn(
f"bool({self!r}) is always True, did you mean to draw a value?",
HypothesisWarning,
stacklevel=2,
)
return True

def validate(self) -> None:
"""Throw an exception if the strategy is not valid.
Expand Down Expand Up @@ -589,7 +598,7 @@ def do_filtered_draw(self, data):
return filter_not_satisfied


class OneOfStrategy(SearchStrategy):
class OneOfStrategy(SearchStrategy[Ex]):
"""Implements a union of strategies. Given a number of strategies this
generates values which could have come from any of them.
Expand Down Expand Up @@ -781,7 +790,7 @@ def one_of(
return OneOfStrategy(args)


class MappedSearchStrategy(SearchStrategy):
class MappedSearchStrategy(SearchStrategy[Ex]):
"""A strategy which is defined purely by conversion to and from another
strategy.
Expand Down Expand Up @@ -816,7 +825,7 @@ def pack(self, x):
into a value suitable for outputting from this strategy."""
raise NotImplementedError(f"{self.__class__.__name__}.pack()")

def do_draw(self, data: ConjectureData) -> Ex:
def do_draw(self, data: ConjectureData) -> Any:
with warnings.catch_warnings():
if isinstance(self.pack, type) and issubclass(
self.pack, (abc.Mapping, abc.Set)
Expand All @@ -826,7 +835,7 @@ def do_draw(self, data: ConjectureData) -> Ex:
i = data.index
try:
data.start_example(MAPPED_SEARCH_STRATEGY_DO_DRAW_LABEL)
result = self.pack(data.draw(self.mapped_strategy))
result = self.pack(data.draw(self.mapped_strategy)) # type: ignore
data.stop_example()
return result
except UnsatisfiedAssumption:
Expand All @@ -846,7 +855,7 @@ def branches(self) -> List[SearchStrategy[Ex]]:
filter_not_satisfied = UniqueIdentifier("filter not satisfied")


class FilteredStrategy(SearchStrategy):
class FilteredStrategy(SearchStrategy[Ex]):
def __init__(self, strategy, conditions):
super().__init__()
if isinstance(strategy, FilteredStrategy):
Expand Down
11 changes: 11 additions & 0 deletions hypothesis-python/tests/cover/test_error_in_draw.py
Expand Up @@ -11,6 +11,7 @@
import pytest

from hypothesis import given, strategies as st
from hypothesis.errors import HypothesisWarning


def test_error_is_in_finally():
Expand All @@ -25,3 +26,13 @@ def test(d):
test()

assert "[0, 1, -1]" in "\n".join(err.value.__notes__)


@given(st.data())
def test_warns_on_bool_strategy(data):
with pytest.warns(
HypothesisWarning,
match=r"bool\(.+\) is always True, did you mean to draw a value\?",
):
if st.booleans(): # 'forgot' to draw from the strategy
pass
9 changes: 8 additions & 1 deletion hypothesis-python/tox.ini
Expand Up @@ -43,7 +43,7 @@ commands=

# Note: when adding or removing tested Pandas versions, make sure to update the
# docs in numpy.rst too. To see current download rates of each minor version:
# https://pepy.tech/project/pandas?versions=0.25.*&versions=1.0.*&versions=1.1.*&versions=1.2.*&versions=1.3.*&versions=1.4.*
# https://pepy.tech/project/pandas?versions=1.0.*&versions=1.1.*&versions=1.2.*&versions=1.3.*&versions=1.4.*&versions=1.5.*
[testenv:pandas10]
deps =
-r../requirements/test.txt
Expand Down Expand Up @@ -78,6 +78,13 @@ deps =
pandas~=1.4.3
commands =
python -bb -X dev -m pytest tests/pandas -n auto

[testenv:pandas15]
deps =
-r../requirements/test.txt
pandas~=1.5.0
commands =
python -bb -X dev -m pytest tests/pandas -n auto
# Adding a new pandas? See comment above!

[testenv:django32]
Expand Down
10 changes: 4 additions & 6 deletions requirements/coverage.txt
Expand Up @@ -18,7 +18,7 @@ click==8.1.3
# via
# -r requirements/coverage.in
# black
coverage==6.4.4
coverage==6.5.0
# via -r requirements/coverage.in
deprecated==1.2.13
# via redis
Expand All @@ -28,7 +28,7 @@ exceptiongroup==1.0.0rc9 ; python_version < "3.11"
# via hypothesis (hypothesis-python/setup.py)
execnet==1.9.0
# via pytest-xdist
fakeredis==1.9.1
fakeredis==1.9.3
# via -r requirements/coverage.in
iniconfig==1.1.1
# via pytest
Expand All @@ -48,7 +48,7 @@ packaging==21.3
# via
# pytest
# redis
pandas==1.4.4
pandas==1.5.0
# via -r requirements/coverage.in
pathspec==0.10.1
# via black
Expand Down Expand Up @@ -88,9 +88,7 @@ pyyaml==6.0
redis==4.3.4
# via fakeredis
six==1.16.0
# via
# fakeredis
# python-dateutil
# via python-dateutil
sortedcontainers==2.4.0
# via
# fakeredis
Expand Down
33 changes: 16 additions & 17 deletions requirements/tools.txt
Expand Up @@ -17,7 +17,7 @@ attrs==22.1.0
# flake8-bugbear
# hypothesis (hypothesis-python/setup.py)
# pytest
autoflake==1.5.3
autoflake==1.6.1
# via shed
babel==2.10.3
# via sphinx
Expand All @@ -35,7 +35,7 @@ bleach==5.0.1
# via readme-renderer
build==0.8.0
# via pip-tools
certifi==2022.9.14
certifi==2022.9.24
# via requests
cffi==1.15.1
# via cryptography
Expand All @@ -51,7 +51,7 @@ com2ann==0.3.0
# via shed
commonmark==0.9.1
# via rich
coverage==6.4.4
coverage==6.5.0
# via -r requirements/tools.in
cryptography==38.0.1
# via secretstorage
Expand All @@ -71,7 +71,7 @@ dpcontracts==0.6.0
# via -r requirements/tools.in
exceptiongroup==1.0.0rc9 ; python_version < "3.11"
# via hypothesis (hypothesis-python/setup.py)
executing==1.0.0
executing==1.1.0
# via stack-data
filelock==3.8.0
# via
Expand All @@ -94,7 +94,7 @@ flake8-2020==1.7.0
# via -r requirements/tools.in
flake8-bandit==4.1.1
# via -r requirements/tools.in
flake8-bugbear==22.9.11
flake8-bugbear==22.9.23
# via -r requirements/tools.in
flake8-builtins==1.5.3
# via -r requirements/tools.in
Expand Down Expand Up @@ -128,7 +128,7 @@ idna==3.4
# via requests
imagesize==1.4.1
# via sphinx
importlib-metadata==4.12.0
importlib-metadata==4.13.0
# via
# keyring
# sphinx
Expand All @@ -139,7 +139,7 @@ ipython==8.5.0
# via -r requirements/tools.in
isort==5.10.1
# via shed
jaraco-classes==3.2.2
jaraco-classes==3.2.3
# via keyring
jedi==0.18.1
# via ipython
Expand All @@ -165,7 +165,7 @@ mccabe==0.7.0
# via flake8
more-itertools==8.14.0
# via jaraco-classes
mypy==0.971
mypy==0.981
# via -r requirements/tools.in
mypy-extensions==0.4.3
# via
Expand Down Expand Up @@ -232,21 +232,21 @@ pygments==2.13.0
# sphinx
pyparsing==3.0.9
# via packaging
pyright==1.1.271
pyright==1.1.273
# via -r requirements/tools.in
pytest==7.1.3
# via -r requirements/tools.in
python-dateutil==2.8.2
# via -r requirements/tools.in
pytz==2022.2.1
# via babel
pyupgrade==2.38.0
pyupgrade==2.38.2
# via shed
pyyaml==6.0
# via
# bandit
# libcst
readme-renderer==37.1
readme-renderer==37.2
# via twine
requests==2.28.1
# via
Expand Down Expand Up @@ -282,7 +282,7 @@ sortedcontainers==2.4.0
# via hypothesis (hypothesis-python/setup.py)
soupsieve==2.3.2.post1
# via beautifulsoup4
sphinx==5.1.1
sphinx==5.2.3
# via
# -r requirements/tools.in
# sphinx-codeautolink
Expand All @@ -308,18 +308,17 @@ sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
sqlparse==0.4.2
sqlparse==0.4.3
# via django
stack-data==0.5.0
stack-data==0.5.1
# via ipython
stevedore==4.0.0
# via bandit
tokenize-rt==4.2.1
# via pyupgrade
toml==0.10.2
# via autoflake
tomli==2.0.1
# via
# autoflake
# black
# build
# mypy
Expand All @@ -340,7 +339,7 @@ types-pkg-resources==0.1.3
# via -r requirements/tools.in
types-pytz==2022.2.1.0
# via -r requirements/tools.in
types-redis==4.3.20
types-redis==4.3.21
# via -r requirements/tools.in
typing-extensions==4.3.0
# via
Expand Down
2 changes: 1 addition & 1 deletion tooling/src/hypothesistooling/__main__.py
Expand Up @@ -440,7 +440,7 @@ def standard_tox_task(name):

for n in [32, 40, 41]:
standard_tox_task(f"django{n}")
for n in [10, 11, 12, 13, 14]:
for n in [10, 11, 12, 13, 14, 15]:
standard_tox_task(f"pandas{n}")

standard_tox_task("coverage")
Expand Down

0 comments on commit 7839707

Please sign in to comment.