Skip to content

Commit 07ff885

Browse files
committed
InferType -> EllipsesType
1 parent bea95f0 commit 07ff885

File tree

4 files changed

+35
-41
lines changed

4 files changed

+35
-41
lines changed

hypothesis-python/src/hypothesis/core.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,15 @@
110110
MappedSearchStrategy,
111111
SearchStrategy,
112112
)
113-
from hypothesis.utils.conventions import infer
114113
from hypothesis.vendor.pretty import RepresentationPrinter
115114
from hypothesis.version import __version__
116115

117116
if sys.version_info >= (3, 10): # pragma: no cover
118-
from types import EllipsisType as InferType
117+
from types import EllipsisType as EllipsisType
119118
elif TYPE_CHECKING:
120-
from builtins import ellipsis as InferType
119+
from builtins import ellipsis as EllipsisType
121120
else:
122-
InferType = type(Ellipsis)
121+
EllipsisType = type(Ellipsis)
123122

124123

125124
TestFunc = TypeVar("TestFunc", bound=Callable)
@@ -292,7 +291,7 @@ def is_invalid_test(test, original_sig, given_arguments, given_kwargs):
292291
f"arguments, but got {len(given_arguments)} {given_arguments!r}"
293292
)
294293

295-
if infer in given_arguments:
294+
if ... in given_arguments:
296295
return invalid(
297296
"... was passed as a positional argument to @given, but may only be "
298297
"passed as a keyword argument or as the sole argument of @given"
@@ -998,7 +997,7 @@ def fuzz_one_input(
998997

999998
@overload
1000999
def given(
1001-
*_given_arguments: Union[SearchStrategy[Any], InferType],
1000+
*_given_arguments: Union[SearchStrategy[Any], EllipsisType],
10021001
) -> Callable[
10031002
[Callable[..., Optional[Coroutine[Any, Any, None]]]], Callable[..., None]
10041003
]: # pragma: no cover
@@ -1007,16 +1006,16 @@ def given(
10071006

10081007
@overload
10091008
def given(
1010-
**_given_kwargs: Union[SearchStrategy[Any], InferType],
1009+
**_given_kwargs: Union[SearchStrategy[Any], EllipsisType],
10111010
) -> Callable[
10121011
[Callable[..., Optional[Coroutine[Any, Any, None]]]], Callable[..., None]
10131012
]: # pragma: no cover
10141013
...
10151014

10161015

10171016
def given(
1018-
*_given_arguments: Union[SearchStrategy[Any], InferType],
1019-
**_given_kwargs: Union[SearchStrategy[Any], InferType],
1017+
*_given_arguments: Union[SearchStrategy[Any], EllipsisType],
1018+
**_given_kwargs: Union[SearchStrategy[Any], EllipsisType],
10201019
) -> Callable[
10211020
[Callable[..., Optional[Coroutine[Any, Any, None]]]], Callable[..., None]
10221021
]:
@@ -1069,9 +1068,9 @@ def run_test_as_given(test):
10691068
new_signature = new_given_signature(original_sig, given_kwargs)
10701069

10711070
# Use type information to convert "infer" arguments into appropriate strategies.
1072-
if infer in given_kwargs.values():
1071+
if ... in given_kwargs.values():
10731072
hints = get_type_hints(test)
1074-
for name in [name for name, value in given_kwargs.items() if value is infer]:
1073+
for name in [name for name, value in given_kwargs.items() if value is ...]:
10751074
if name not in hints:
10761075
return _invalid(
10771076
f"passed {name}=... for {test.__name__}, but {name} has "

hypothesis-python/src/hypothesis/extra/django/_impl.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
from hypothesis.extra.django._fields import from_field
2525
from hypothesis.internal.reflection import define_function_signature
2626
from hypothesis.strategies._internal.utils import defines_strategy
27-
from hypothesis.utils.conventions import infer
2827

2928
if sys.version_info >= (3, 10): # pragma: no cover
30-
from types import EllipsisType as InferType
29+
from types import EllipsisType as EllipsisType
3130
elif TYPE_CHECKING:
32-
from builtins import ellipsis as InferType
31+
from builtins import ellipsis as EllipsisType
3332
else:
34-
InferType = type(Ellipsis)
33+
EllipsisType = type(Ellipsis)
3534

3635

3736
class HypothesisTestCase:
@@ -67,7 +66,7 @@ class StaticLiveServerTestCase(HypothesisTestCase, dst.StaticLiveServerTestCase)
6766

6867
@defines_strategy()
6968
def from_model(
70-
*model: Type[dm.Model], **field_strategies: Union[st.SearchStrategy, InferType]
69+
*model: Type[dm.Model], **field_strategies: Union[st.SearchStrategy, EllipsisType]
7170
) -> st.SearchStrategy:
7271
"""Return a strategy for examples of ``model``.
7372
@@ -106,7 +105,7 @@ def from_model(
106105

107106
fields_by_name = {f.name: f for f in m_type._meta.concrete_fields}
108107
for name, value in sorted(field_strategies.items()):
109-
if value is infer:
108+
if value is ...:
110109
field_strategies[name] = from_field(fields_by_name[name])
111110
for name, field in sorted(fields_by_name.items()):
112111
if (
@@ -157,7 +156,7 @@ def _models_impl(draw, strat):
157156
def from_form(
158157
form: Type[df.Form],
159158
form_kwargs: Optional[dict] = None,
160-
**field_strategies: Union[st.SearchStrategy, InferType],
159+
**field_strategies: Union[st.SearchStrategy, EllipsisType],
161160
) -> st.SearchStrategy[df.Form]:
162161
"""Return a strategy for examples of ``form``.
163162
@@ -214,7 +213,7 @@ def from_form(
214213
else:
215214
fields_by_name[name] = field
216215
for name, value in sorted(field_strategies.items()):
217-
if value is infer:
216+
if value is ...:
218217
field_strategies[name] = from_field(fields_by_name[name])
219218

220219
for name, field in sorted(fields_by_name.items()):

hypothesis-python/src/hypothesis/extra/ghostwriter.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,13 @@
116116
SampledFromStrategy,
117117
)
118118
from hypothesis.strategies._internal.types import _global_type_lookup, is_generic_type
119-
from hypothesis.utils.conventions import infer
120119

121120
if sys.version_info >= (3, 10): # pragma: no cover
122-
from types import EllipsisType as InferType
121+
from types import EllipsisType as EllipsisType
123122
elif TYPE_CHECKING:
124-
from builtins import ellipsis as InferType
123+
from builtins import ellipsis as EllipsisType
125124
else:
126-
InferType = type(Ellipsis)
125+
EllipsisType = type(Ellipsis)
127126

128127

129128
IMPORT_SECTION = """
@@ -252,10 +251,7 @@ def _type_from_doc_fragment(token: str) -> Optional[type]:
252251
return getattr(sys.modules.get(mod, None), name, None)
253252

254253

255-
def _strategy_for(
256-
param: inspect.Parameter,
257-
docstring: str,
258-
) -> Union[st.SearchStrategy, InferType]:
254+
def _strategy_for(param: inspect.Parameter, docstring: str) -> st.SearchStrategy:
259255
# Example types in docstrings:
260256
# - `:type a: sequence of integers`
261257
# - `b (list, tuple, or None): ...`
@@ -532,7 +528,7 @@ def _get_strategies(
532528
hints = get_type_hints(f)
533529
docstring = getattr(f, "__doc__", None) or ""
534530
builder_args = {
535-
k: infer if k in hints else _strategy_for(v, docstring)
531+
k: ... if k in hints else _strategy_for(v, docstring)
536532
for k, v in params.items()
537533
}
538534
with _with_any_registered():
@@ -1323,7 +1319,7 @@ def binary_operation(
13231319
*,
13241320
associative: bool = True,
13251321
commutative: bool = True,
1326-
identity: Union[X, InferType, None] = infer,
1322+
identity: Union[X, EllipsisType, None] = ...,
13271323
distributes_over: Optional[Callable[[X, X], X]] = None,
13281324
except_: Except = (),
13291325
style: str = "pytest",
@@ -1384,7 +1380,7 @@ def _make_binop_body(
13841380
*,
13851381
associative: bool = True,
13861382
commutative: bool = True,
1387-
identity: Union[X, InferType, None] = infer,
1383+
identity: Union[X, EllipsisType, None] = ...,
13881384
distributes_over: Optional[Callable[[X, X], X]] = None,
13891385
except_: Tuple[Type[Exception], ...],
13901386
style: str,
@@ -1454,7 +1450,7 @@ def maker(
14541450
# Guess that the identity element is the minimal example from our operands
14551451
# strategy. This is correct often enough to be worthwhile, and close enough
14561452
# that it's a good starting point to edit much of the rest.
1457-
if identity is infer:
1453+
if identity is ...:
14581454
try:
14591455
identity = find(operands, lambda x: True, settings=_quietly_settings)
14601456
except Exception:

hypothesis-python/src/hypothesis/strategies/_internal/core.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@
114114
TextStrategy,
115115
)
116116
from hypothesis.strategies._internal.utils import cacheable, defines_strategy
117-
from hypothesis.utils.conventions import infer, not_set
117+
from hypothesis.utils.conventions import not_set
118118

119119
if sys.version_info >= (3, 10): # pragma: no cover
120-
from types import EllipsisType as InferType
120+
from types import EllipsisType as EllipsisType
121121
elif typing.TYPE_CHECKING: # pragma: no cover
122-
from builtins import ellipsis as InferType
122+
from builtins import ellipsis as EllipsisType
123123
else:
124-
InferType = type(Ellipsis)
124+
EllipsisType = type(Ellipsis)
125125

126126

127127
try:
@@ -863,7 +863,7 @@ def __repr__(self):
863863
@defines_strategy()
864864
def builds(
865865
*callable_and_args: Union[Callable[..., Ex], SearchStrategy[Any]],
866-
**kwargs: Union[SearchStrategy[Any], InferType],
866+
**kwargs: Union[SearchStrategy[Any], EllipsisType],
867867
) -> SearchStrategy[Ex]:
868868
"""Generates values by drawing from ``args`` and ``kwargs`` and passing
869869
them to the callable (provided as the first positional argument) in the
@@ -898,14 +898,14 @@ def builds(
898898
"target to construct."
899899
)
900900

901-
if infer in args: # type: ignore # we only annotated the allowed types
901+
if ... in args: # type: ignore # we only annotated the allowed types
902902
# Avoid an implementation nightmare juggling tuples and worse things
903903
raise InvalidArgument(
904904
"... was passed as a positional argument to "
905905
"builds(), but is only allowed as a keyword arg"
906906
)
907907
required = required_args(target, args, kwargs)
908-
to_infer = {k for k, v in kwargs.items() if v is infer}
908+
to_infer = {k for k, v in kwargs.items() if v is ...}
909909
if required or to_infer:
910910
if isinstance(target, type) and attr.has(target):
911911
# Use our custom introspection for attrs classes
@@ -1993,7 +1993,7 @@ def _functions(*, like, returns, pure):
19931993
"The first argument to functions() must be a callable to imitate, "
19941994
f"but got non-callable like={nicerepr(like)!r}"
19951995
)
1996-
if returns is None or returns is infer:
1996+
if returns in (None, ...):
19971997
# Passing `None` has never been *documented* as working, but it still
19981998
# did from May 2020 to Jan 2022 so we'll avoid breaking it without cause.
19991999
hints = get_type_hints(like)
@@ -2036,7 +2036,7 @@ def functions(
20362036
...
20372037

20382038
@defines_strategy()
2039-
def functions(*, like=lambda: None, returns=infer, pure=False):
2039+
def functions(*, like=lambda: None, returns=..., pure=False):
20402040
# We shouldn't need overloads here, but mypy disallows default args for
20412041
# generics: https://github.com/python/mypy/issues/3737
20422042
"""functions(*, like=lambda: None, returns=..., pure=False)
@@ -2067,7 +2067,7 @@ def functions(*, like=lambda: None, returns=infer, pure=False):
20672067
def functions(
20682068
*,
20692069
like: Callable[..., Any] = lambda: None,
2070-
returns: Union[SearchStrategy[Any], InferType] = infer,
2070+
returns: Union[SearchStrategy[Any], EllipsisType] = ...,
20712071
pure: bool = False,
20722072
) -> SearchStrategy[Callable[..., Any]]:
20732073
"""functions(*, like=lambda: None, returns=..., pure=False)

0 commit comments

Comments
 (0)