Skip to content

Commit

Permalink
tidy defines_strategy decorators HypothesisWorks#2516
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnsw-felixs authored and Zac-HD committed Sep 6, 2020
1 parent 8959b55 commit 1bf75ed
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 68 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -41,6 +41,7 @@ their individual contributions.
* `El Awbery <https://www.github.com/ElAwbery>`_
* `Emmanuel Leblond <https://www.github.com/touilleMan>`_
* `Felix Grünewald <https://www.github.com/fgruen>`_
* `Felix Sheldon <https://www.github.com/darkpaw>`_
* `Florian Bruhin <https://www.github.com/The-Compiler>`_
* `follower <https://www.github.com/follower>`_
* `Gary Donovan <https://www.github.com/garyd203>`_
Expand Down
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch contains some internal refactoring.
Thanks to Felix Sheldon for fixing :issue:`2516`!
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/dateutil.py
Expand Up @@ -44,7 +44,7 @@ def __zone_sort_key(zone):


@st.cacheable
@st.defines_strategy
@st.defines_strategy()
def timezones() -> st.SearchStrategy[dt.tzinfo]:
"""Any timezone from :pypi:`dateutil <python-dateutil>`.
Expand Down
4 changes: 2 additions & 2 deletions hypothesis-python/src/hypothesis/extra/django/_impl.py
Expand Up @@ -54,7 +54,7 @@ class TransactionTestCase(HypothesisTestCase, dt.TransactionTestCase):
pass


@st.defines_strategy
@st.defines_strategy()
def from_model(
*model: Type[dm.Model], **field_strategies: Union[st.SearchStrategy, InferType]
) -> st.SearchStrategy:
Expand Down Expand Up @@ -146,7 +146,7 @@ def _models_impl(draw, strat):
reject()


@st.defines_strategy
@st.defines_strategy()
def from_form(
form: Type[df.Form],
form_kwargs: dict = None,
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/lark.py
Expand Up @@ -193,7 +193,7 @@ def inner(value):


@st.cacheable
@st.defines_strategy_with_reusable_values
@st.defines_strategy(force_reusable_values=True)
@deprecated_posargs
def from_lark(
grammar: lark.lark.Lark,
Expand Down
22 changes: 11 additions & 11 deletions hypothesis-python/src/hypothesis/extra/numpy.py
Expand Up @@ -40,7 +40,7 @@
TIME_RESOLUTIONS = tuple("Y M D h m s ms us ns ps fs as".split())


@st.defines_strategy_with_reusable_values
@st.defines_strategy(force_reusable_values=True)
def from_dtype(dtype: np.dtype) -> st.SearchStrategy[Any]:
"""Creates a strategy which can generate any value of the given dtype."""
check_type(np.dtype, dtype, "dtype")
Expand Down Expand Up @@ -297,7 +297,7 @@ def fill_for(elements, unique, fill, name=""):
return fill


@st.defines_strategy
@st.defines_strategy(force_reusable_values=True)
@deprecated_posargs
def arrays(
dtype: Any,
Expand Down Expand Up @@ -416,7 +416,7 @@ def arrays(
return ArrayStrategy(elements, shape, dtype, fill, unique)


@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def array_shapes(
*, min_dims: int = 1, max_dims: int = None, min_side: int = 1, max_side: int = None
Expand Down Expand Up @@ -448,7 +448,7 @@ def array_shapes(
).map(tuple)


@st.defines_strategy
@st.defines_strategy()
def scalar_dtypes() -> st.SearchStrategy[np.dtype]:
"""Return a strategy that can return any non-flexible scalar dtype."""
return st.one_of(
Expand All @@ -463,7 +463,7 @@ def scalar_dtypes() -> st.SearchStrategy[np.dtype]:


def defines_dtype_strategy(strat: T) -> T:
@st.defines_strategy
@st.defines_strategy()
@proxies(strat)
def inner(*args, **kwargs):
return strat(*args, **kwargs).map(np.dtype)
Expand Down Expand Up @@ -703,7 +703,7 @@ def array_dtypes(
).filter(_no_title_is_name_of_a_titled_field)


@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def nested_dtypes(
subtype_strategy: st.SearchStrategy[np.dtype] = scalar_dtypes(),
Expand All @@ -726,7 +726,7 @@ def nested_dtypes(
).filter(lambda d: max_itemsize is None or d.itemsize <= max_itemsize)


@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def valid_tuple_axes(
ndim: int, *, min_size: int = 0, max_size: int = None
Expand Down Expand Up @@ -775,7 +775,7 @@ def valid_tuple_axes(
).map(tuple)


@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def broadcastable_shapes(
shape: Shape,
Expand Down Expand Up @@ -1095,7 +1095,7 @@ def _hypothesis_parse_gufunc_signature(signature, all_checks=True):
return _GUfuncSig(input_shapes=input_shapes, result_shape=result_shape)


@st.defines_strategy
@st.defines_strategy()
def mutually_broadcastable_shapes(
*,
num_shapes: Union[UniqueIdentifier, int] = not_set,
Expand Down Expand Up @@ -1321,7 +1321,7 @@ def do_draw(self, data):
return tuple(result)


@st.defines_strategy
@st.defines_strategy()
def basic_indices(
shape: Shape,
*,
Expand Down Expand Up @@ -1386,7 +1386,7 @@ def basic_indices(
)


@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def integer_array_indices(
shape: Shape,
Expand Down
8 changes: 4 additions & 4 deletions hypothesis-python/src/hypothesis/extra/pandas/impl.py
Expand Up @@ -152,7 +152,7 @@ def do_draw(self, data):


@st.cacheable
@st.defines_strategy
@st.defines_strategy()
def range_indexes(
min_size: int = 0, max_size: int = None
) -> st.SearchStrategy[pandas.RangeIndex]:
Expand All @@ -174,7 +174,7 @@ def range_indexes(


@st.cacheable
@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def indexes(
*,
Expand Down Expand Up @@ -215,7 +215,7 @@ def indexes(
return ValueIndexStrategy(elements, dtype, min_size, max_size, unique)


@st.defines_strategy
@st.defines_strategy()
@deprecated_posargs
def series(
*,
Expand Down Expand Up @@ -361,7 +361,7 @@ def columns(


@deprecated_posargs
@st.defines_strategy
@st.defines_strategy()
def data_frames(
columns: Sequence[column] = None,
*,
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/pytz.py
Expand Up @@ -36,7 +36,7 @@


@st.cacheable
@st.defines_strategy
@st.defines_strategy()
def timezones() -> st.SearchStrategy[dt.tzinfo]:
"""Any timezone in the Olsen database, as a pytz tzinfo object.
Expand Down
8 changes: 4 additions & 4 deletions hypothesis-python/src/hypothesis/provisional.py
Expand Up @@ -134,7 +134,7 @@ def do_draw(self, data):
return domain


@st.defines_strategy_with_reusable_values
@st.defines_strategy(force_reusable_values=True)
@deprecated_posargs
def domains(
*, max_length: int = 255, max_element_length: int = 63
Expand All @@ -145,7 +145,7 @@ def domains(
)


@st.defines_strategy_with_reusable_values
@st.defines_strategy(force_reusable_values=True)
def urls() -> SearchStrategy[str]:
"""A strategy for :rfc:`3986`, generating http/https URLs."""

Expand All @@ -161,7 +161,7 @@ def url_encode(s):
)


@st.defines_strategy_with_reusable_values
@st.defines_strategy(force_reusable_values=True)
def ip4_addr_strings() -> SearchStrategy[str]:
note_deprecation(
"Use `ip_addresses(v=4).map(str)` instead of `ip4_addr_strings()`; "
Expand All @@ -171,7 +171,7 @@ def ip4_addr_strings() -> SearchStrategy[str]:
return ip_addresses(v=4).map(str)


@st.defines_strategy_with_reusable_values
@st.defines_strategy(force_reusable_values=True)
def ip6_addr_strings() -> SearchStrategy[str]:
note_deprecation(
"Use `ip_addresses(v=6).map(str)` instead of `ip6_addr_strings()`; "
Expand Down

0 comments on commit 1bf75ed

Please sign in to comment.