Skip to content

Commit

Permalink
Updated PR with suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksspirit committed Apr 24, 2023
1 parent f8e4e74 commit e417373
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ their individual contributions.
* `Munir Abdinur <https://www.github.com/mabdinur>`_
* `Nicholas Chammas <https://www.github.com/nchammas>`_
* `Nick Anyos <https://www.github.com/NickAnyos>`_
* `Nick Muoh <https://github.com/OdinTech3>`_ ([email protected])
* `Nicolas Ganz <https://www.github.com/ThunderKey>`_
* `Nikita Sobolev <https://github.com/sobolevn>`_ ([email protected])
* `Oleg Höfling <https://github.com/hoefling>`_ ([email protected])
Expand Down Expand Up @@ -183,4 +184,3 @@ their individual contributions.
* `Yiyang Zhan <https://www.github.com/zhanpon>`_
* `Zac Hatfield-Dodds <https://www.github.com/Zac-HD>`_ ([email protected])
* `Zebulun Arendsee <https://www.github.com/arendsee>`_ ([email protected])
* `Nick Muoh <https://github.com/OdinTech3>`_ ([email protected])
6 changes: 4 additions & 2 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RELEASE_TYPE: patch

This patch fixes the issue https://github.com/HypothesisWorks/hypothesis/issues/3527
allowing builtin types i.e tuple to be used in strategies.
This patch fixes a bug with :func:`~hypothesis.strategies.from_type()` with ``dict[tuple[int, int], str]``
(:issue:`3527`).

Thanks to Nick Muoh at the PyCon Sprints!
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

from hypothesis import strategies as st
from hypothesis.errors import InvalidArgument, ResolutionFailed
from hypothesis.internal.compat import PYPY, BaseExceptionGroup, ExceptionGroup, get_origin
from hypothesis.internal.compat import (
PYPY,
BaseExceptionGroup,
ExceptionGroup,
get_origin,
)
from hypothesis.internal.conjecture.utils import many as conjecture_utils_many
from hypothesis.strategies._internal.datetime import zoneinfo # type: ignore
from hypothesis.strategies._internal.ipaddress import (
Expand Down
20 changes: 20 additions & 0 deletions hypothesis-python/tests/cover/test_lookup_py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,23 @@ def test_issue_3080():
s = st.from_type(typing.Union[list[int], int])
find_any(s, lambda x: isinstance(x, int))
find_any(s, lambda x: isinstance(x, list))


@dataclasses.dataclass
class TypingTuple:
a: dict[typing.Tuple[int, int], str]


@dataclasses.dataclass
class BuiltinTuple:
a: dict[tuple[int, int], str]


TestDataClass = typing.Union[TypingTuple, BuiltinTuple]


@pytest.mark.parametrize("data_class", [TypingTuple, BuiltinTuple])
@given(data=st.data())
def test_from_type_with_tuple_works(data, data_class: TestDataClass):
value: TestDataClass = data.draw(st.from_type(data_class))
assert len(value.a) >= 0
25 changes: 2 additions & 23 deletions hypothesis-python/tests/nocover/test_type_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.

from typing import Callable, Tuple
from dataclasses import dataclass
from typing import Callable

import pytest

from hypothesis import given, strategies as st
from hypothesis import strategies as st
from hypothesis.errors import InvalidArgument
from hypothesis.internal.compat import Concatenate, ParamSpec
from hypothesis.strategies._internal.types import NON_RUNTIME_TYPES
Expand Down Expand Up @@ -83,23 +82,3 @@ def test_callable_return_typegard_type():

with pytest.raises(InvalidArgument, match="Cannot register generic type"):
st.register_type_strategy(Callable[[], TypeGuard[int]], st.none())


@dataclass
class ItWorks:
a: dict[Tuple[int, int], str]


@dataclass
class ItDoesnt:
a: dict[tuple[int, int], str]


@given(st.from_type(ItWorks))
def test_tuple_from_typing_works(x: ItWorks):
assert len(x.a) >= 0


@given(st.from_type(ItDoesnt))
def test_tuple_from_builtin_works(x: ItDoesnt):
assert len(x.a) >= 0
2 changes: 1 addition & 1 deletion hypothesis-python/tests/pytest/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# obtain one at https://mozilla.org/MPL/2.0/.

import pytest
from _hypothesis_pytestplugin import LOAD_PROFILE_OPTION

from _hypothesis_pytestplugin import LOAD_PROFILE_OPTION
from hypothesis.version import __version__

pytest_plugins = "pytester"
Expand Down
1 change: 1 addition & 0 deletions hypothesis-python/tests/pytest/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# obtain one at https://mozilla.org/MPL/2.0/.

import pytest

from _hypothesis_pytestplugin import PRINT_STATISTICS_OPTION

pytest_plugins = "pytester"
Expand Down

0 comments on commit e417373

Please sign in to comment.