Skip to content

Commit

Permalink
Support from_type(Tuple[()])
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Sep 17, 2018
1 parent c4840df commit 6eede4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch allows :func:`~hypothesis.strategies.from_type` to handle the
empty tuple type, :class:`typing.Tuple[()] <python:typing.Tuple>`.
2 changes: 2 additions & 0 deletions hypothesis-python/src/hypothesis/searchstrategy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def from_typing_type(thing):
if getattr(thing, '__tuple_use_ellipsis__', False) or \
len(elem_types) == 2 and elem_types[-1] is Ellipsis:
return st.lists(st.from_type(elem_types[0])).map(tuple)
elif len(elem_types) == 1 and elem_types[0] == ():
return st.tuples() # Empty tuple; see issue #1583
return st.tuples(*map(st.from_type, elem_types))
if isinstance(thing, typing.TypeVar):
if getattr(thing, '__bound__', None) is not None:
Expand Down
6 changes: 6 additions & 0 deletions hypothesis-python/tests/py3/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,9 @@ def test_resolving_recursive_type():
# https://github.com/HypothesisWorks/hypothesis-python/issues/1074
assert sys.version_info[:2] == (3, 5)
pytest.skip('Could not find type hints to resolve')


@given(from_type(typing.Tuple[()]))
def test_resolves_empty_Tuple_issue_1583_regression(ex):
# See e.g. https://github.com/python/mypy/commit/71332d58
assert ex == ()

0 comments on commit 6eede4a

Please sign in to comment.