Skip to content

Commit

Permalink
Merge pull request #3622 from OdinTech3/master
Browse files Browse the repository at this point in the history
Fix Strategy from_type failure.
  • Loading branch information
Zac-HD authored Apr 25, 2023
2 parents fa713da + c6b9b32 commit 7a33299
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions 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
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RELEASE_TYPE: patch

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
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 Expand Up @@ -423,7 +428,7 @@ def from_typing_type(thing):
else:
union_elems = ()
if not any(
isinstance(T, type) and issubclass(int, T)
isinstance(T, type) and issubclass(int, get_origin(T) or T)
for T in list(union_elems) + [elem_type]
):
mapping.pop(typing.ByteString, None)
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

0 comments on commit 7a33299

Please sign in to comment.