Skip to content

Commit 3def0a6

Browse files
authored
Merge pull request #3722 from HypothesisWorks/create-pull-request/patch
Update pinned dependencies
2 parents e20023b + 2930fb2 commit 3def0a6

File tree

90 files changed

+380
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+380
-328
lines changed

hypothesis-python/RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch enables and fixes many more of :pypi:`ruff`\ 's lint rules.

hypothesis-python/examples/test_binary_search.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ def binary_search(ls, v):
7070

7171
def is_sorted(ls):
7272
"""Is this list sorted?"""
73-
for i in range(len(ls) - 1):
74-
if ls[i] > ls[i + 1]:
75-
return False
76-
return True
73+
return all(x <= y for x, y in zip(ls, ls[1:]))
7774

7875

7976
Values = st.integers()

hypothesis-python/setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def local_file(name):
3737
warnings.warn(
3838
"This version of setuptools is too old to handle license_files "
3939
"metadata key. For more info, see: "
40-
"https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#metadata"
40+
"https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#metadata",
41+
stacklevel=1,
4142
)
4243

4344

hypothesis-python/src/_hypothesis_pytestplugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __call__(self, msg):
9191
Note that the pytest developers no longer support your version either!
9292
Disabling the Hypothesis pytest plugin...
9393
"""
94-
warnings.warn(PYTEST_TOO_OLD_MESSAGE % (pytest.__version__,))
94+
warnings.warn(PYTEST_TOO_OLD_MESSAGE % (pytest.__version__,), stacklevel=1)
9595

9696
else:
9797

hypothesis-python/src/hypothesis/_settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def _define_setting(
231231
cls,
232232
name,
233233
description,
234+
*,
234235
default,
235236
options=None,
236237
validator=None,

hypothesis-python/src/hypothesis/control.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def reject() -> NoReturn:
27-
raise UnsatisfiedAssumption()
27+
raise UnsatisfiedAssumption
2828

2929

3030
def assume(condition: object) -> bool:
@@ -35,7 +35,7 @@ def assume(condition: object) -> bool:
3535
true, and let Hypothesis try to avoid similar examples in future.
3636
"""
3737
if not condition:
38-
raise UnsatisfiedAssumption()
38+
raise UnsatisfiedAssumption
3939
return True
4040

4141

@@ -62,7 +62,7 @@ def current_build_context() -> "BuildContext":
6262

6363

6464
class BuildContext:
65-
def __init__(self, data, is_final=False, close_on_capture=True):
65+
def __init__(self, data, *, is_final=False, close_on_capture=True):
6666
assert isinstance(data, ConjectureData)
6767
self.data = data
6868
self.tasks = []

hypothesis-python/src/hypothesis/core.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ def __init__(self, test_runner, stuff, test, settings, random, wrapped_test):
694694
def execute_once(
695695
self,
696696
data,
697+
*,
697698
print_example=False,
698699
is_final=False,
699700
expected_failure=None,
@@ -1493,7 +1494,7 @@ def find(
14931494
def test(v):
14941495
if condition(v):
14951496
last[:] = [v]
1496-
raise Found()
1497+
raise Found
14971498

14981499
if random is not None:
14991500
test = seed(random.getrandbits(64))(test)

hypothesis-python/src/hypothesis/database.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def _db_for_path(path=None):
6161
path = storage_directory("examples")
6262
if not _usable_dir(path): # pragma: no cover
6363
warnings.warn(
64-
HypothesisWarning(
65-
"The database setting is not configured, and the default "
66-
"location is unusable - falling back to an in-memory "
67-
f"database for this session. {path=}"
68-
)
64+
"The database setting is not configured, and the default "
65+
"location is unusable - falling back to an in-memory "
66+
f"database for this session. {path=}",
67+
HypothesisWarning,
68+
stacklevel=3,
6969
)
7070
return InMemoryExampleDatabase()
7171
if path in (None, ":memory:"):
@@ -488,11 +488,11 @@ def _prepare_for_io(self) -> None:
488488
self._access_cache[keypath].add(PurePath(filename))
489489
except BadZipFile:
490490
warnings.warn(
491-
HypothesisWarning(
492-
"The downloaded artifact from GitHub is invalid. "
493-
"This could be because the artifact was corrupted, "
494-
"or because the artifact was not created by Hypothesis. "
495-
)
491+
"The downloaded artifact from GitHub is invalid. "
492+
"This could be because the artifact was corrupted, "
493+
"or because the artifact was not created by Hypothesis. ",
494+
HypothesisWarning,
495+
stacklevel=3,
496496
)
497497
self._disabled = True
498498

@@ -534,18 +534,17 @@ def _initialize_db(self) -> None:
534534
self._artifact = new_artifact
535535
elif found_artifact is not None:
536536
warnings.warn(
537-
HypothesisWarning(
538-
"Using an expired artifact as a fallback for the database: "
539-
f"{found_artifact}"
540-
)
537+
"Using an expired artifact as a fallback for the database: "
538+
f"{found_artifact}",
539+
HypothesisWarning,
540+
stacklevel=2,
541541
)
542542
self._artifact = found_artifact
543543
else:
544544
warnings.warn(
545-
HypothesisWarning(
546-
"Couldn't acquire a new or existing artifact. "
547-
"Disabling database."
548-
)
545+
"Couldn't acquire a new or existing artifact. Disabling database.",
546+
HypothesisWarning,
547+
stacklevel=2,
549548
)
550549
self._disabled = True
551550
return
@@ -587,7 +586,7 @@ def _get_bytes(self, url: str) -> Optional[bytes]: # pragma: no cover
587586
)
588587

589588
if warning_message is not None:
590-
warnings.warn(HypothesisWarning(warning_message))
589+
warnings.warn(warning_message, HypothesisWarning, stacklevel=4)
591590
return None
592591

593592
return response_bytes
@@ -624,7 +623,9 @@ def _fetch_artifact(self) -> Optional[Path]: # pragma: no cover
624623
f.write(artifact_bytes)
625624
except OSError:
626625
warnings.warn(
627-
HypothesisWarning("Could not save the latest artifact from GitHub. ")
626+
"Could not save the latest artifact from GitHub. ",
627+
HypothesisWarning,
628+
stacklevel=3,
628629
)
629630
return None
630631

hypothesis-python/src/hypothesis/executors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def default_executor(function): # pragma: nocover
13-
raise NotImplementedError() # We don't actually use this any more
13+
raise NotImplementedError # We don't actually use this any more
1414

1515

1616
def setup_teardown_executor(setup, teardown):

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def broadcastable_shapes(
275275
# We are unsure if gufuncs allow frozen dimensions to be optional, but it's
276276
# easy enough to support here - and so we will unless we learn otherwise.
277277
_DIMENSION = r"\w+\??" # Note that \w permits digits too!
278-
_SHAPE = rf"\((?:{_DIMENSION}(?:,{_DIMENSION})" + r"{0,31})?\)"
278+
_SHAPE = rf"\((?:{_DIMENSION}(?:,{_DIMENSION}){{0,31}})?\)"
279279
_ARGUMENT_LIST = f"{_SHAPE}(?:,{_SHAPE})*"
280280
_SIGNATURE = rf"^{_ARGUMENT_LIST}->{_SHAPE}$"
281281
_SIGNATURE_MULTIPLE_OUTPUT = rf"^{_ARGUMENT_LIST}->{_ARGUMENT_LIST}$"
@@ -286,7 +286,7 @@ class _GUfuncSig(NamedTuple):
286286
result_shape: Shape
287287

288288

289-
def _hypothesis_parse_gufunc_signature(signature, all_checks=True):
289+
def _hypothesis_parse_gufunc_signature(signature, *, all_checks=True):
290290
# Disable all_checks to better match the Numpy version, for testing
291291
if not re.match(_SIGNATURE, signature):
292292
if re.match(_SIGNATURE_MULTIPLE_OUTPUT, signature):

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def warn_on_missing_dtypes(xp: Any, stubs: List[str]) -> None:
114114
f"Array module {xp.__name__} does not have the following "
115115
f"dtypes in its namespace: {f_stubs}",
116116
HypothesisWarning,
117+
stacklevel=3,
117118
)
118119

119120

@@ -450,9 +451,7 @@ def do_draw(self, data):
450451
else:
451452
self.check_set_value(val, val_0d, self.elements_strategy)
452453

453-
result = self.xp.reshape(result, self.shape)
454-
455-
return result
454+
return self.xp.reshape(result, self.shape)
456455

457456

458457
def _arrays(
@@ -911,6 +910,7 @@ def make_strategies_namespace(
911910
warn(
912911
f"Could not determine whether module {xp.__name__} is an Array API library",
913912
HypothesisWarning,
913+
stacklevel=2,
914914
)
915915

916916
try:
@@ -1013,7 +1013,7 @@ def floating_dtypes(
10131013
class StrategiesNamespace(SimpleNamespace):
10141014
def __init__(self, **kwargs):
10151015
for attr in ["name", "api_version"]:
1016-
if attr not in kwargs.keys():
1016+
if attr not in kwargs:
10171017
raise ValueError(f"'{attr}' kwarg required")
10181018
super().__init__(**kwargs)
10191019

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,9 @@ def _guess_strategy_by_argname(name: str) -> st.SearchStrategy:
435435
return st.nothing()
436436

437437
if (
438-
name.endswith("_name")
438+
name.endswith(("_name", "label"))
439439
or (name.endswith("name") and "_" not in name)
440440
or ("string" in name and "as" not in name)
441-
or name.endswith("label")
442441
or name in STRING_NAMES
443442
):
444443
return st.text()
@@ -747,7 +746,7 @@ def _get_module(obj):
747746
raise RuntimeError(f"Could not find module for ufunc {obj.__name__} ({obj!r}")
748747

749748

750-
def _get_qualname(obj, include_module=False):
749+
def _get_qualname(obj, *, include_module=False):
751750
# Replacing angle-brackets for objects defined in `.<locals>.`
752751
qname = getattr(obj, "__qualname__", obj.__name__)
753752
qname = qname.replace("<", "_").replace(">", "_").replace(" ", "")

hypothesis-python/src/hypothesis/internal/cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def new_entry(self, key, value):
162162
163163
Returns the score to associate with the key.
164164
"""
165-
raise NotImplementedError()
165+
raise NotImplementedError
166166

167167
def on_access(self, key, value, score):
168168
"""Called every time a key that is already in the map is read or

hypothesis-python/src/hypothesis/internal/conjecture/choicetree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def choose(
8989
node.children[i] = DeadNode
9090
node.live_child_count -= 1
9191
assert node.live_child_count == 0
92-
raise DeadBranch()
92+
raise DeadBranch
9393

9494
def finish(self) -> Sequence[int]:
9595
"""Record the decisions made in the underlying tree and return

hypothesis-python/src/hypothesis/internal/conjecture/data.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,27 @@ def run(self) -> Any:
240240
self.bytes_read = blocks.endpoints[self.block_count]
241241
self.block(self.block_count)
242242
self.block_count += 1
243-
self.__pop(False)
243+
self.__pop(discarded=False)
244244
elif record >= START_EXAMPLE_RECORD:
245245
self.__push(record - START_EXAMPLE_RECORD)
246246
else:
247247
assert record in (
248248
STOP_EXAMPLE_DISCARD_RECORD,
249249
STOP_EXAMPLE_NO_DISCARD_RECORD,
250250
)
251-
self.__pop(record == STOP_EXAMPLE_DISCARD_RECORD)
251+
self.__pop(discarded=record == STOP_EXAMPLE_DISCARD_RECORD)
252252
return self.finish()
253253

254254
def __push(self, label_index: int) -> None:
255255
i = self.example_count
256256
assert i < len(self.examples)
257-
self.start_example(i, label_index)
257+
self.start_example(i, label_index=label_index)
258258
self.example_count += 1
259259
self.example_stack.append(i)
260260

261-
def __pop(self, discarded: bool) -> None:
261+
def __pop(self, *, discarded: bool) -> None:
262262
i = self.example_stack.pop()
263-
self.stop_example(i, discarded)
263+
self.stop_example(i, discarded=discarded)
264264

265265
def begin(self) -> None:
266266
"""Called at the beginning of the run to initialise any
@@ -276,7 +276,7 @@ def block(self, i: int) -> None:
276276
"""Called with each ``draw_bits`` call, with ``i`` the index of the
277277
corresponding block in ``self.examples.blocks``"""
278278

279-
def stop_example(self, i: int, discarded: bool) -> None:
279+
def stop_example(self, i: int, *, discarded: bool) -> None:
280280
"""Called at the end of each example, with ``i`` the
281281
index of the example and ``discarded`` being ``True`` if ``stop_example``
282282
was called with ``discard=True``."""
@@ -342,7 +342,7 @@ def start_example(self, label: int) -> None:
342342
self.labels.append(label)
343343
self.trail.append(START_EXAMPLE_RECORD + i)
344344

345-
def stop_example(self, discard: bool) -> None:
345+
def stop_example(self, *, discard: bool) -> None:
346346
if discard:
347347
self.trail.append(STOP_EXAMPLE_DISCARD_RECORD)
348348
else:
@@ -382,7 +382,7 @@ def begin(self):
382382
def start_example(self, i: int, label_index: int) -> None:
383383
self.starts[i] = self.bytes_read
384384

385-
def stop_example(self, i: int, discarded: bool) -> None:
385+
def stop_example(self, i: int, *, discarded: bool) -> None:
386386
self.ends[i] = self.bytes_read
387387

388388
def finish(self) -> Tuple[IntList, IntList]:
@@ -407,7 +407,7 @@ def begin(self) -> None:
407407
def finish(self) -> FrozenSet[int]:
408408
return frozenset(self.result)
409409

410-
def stop_example(self, i: int, discarded: bool) -> None:
410+
def stop_example(self, i: int, *, discarded: bool) -> None:
411411
if discarded:
412412
self.result.add(i)
413413

@@ -422,7 +422,7 @@ def block(self, i: int) -> None:
422422
if not self.examples.blocks.trivial(i):
423423
self.nontrivial[self.example_stack[-1]] = 1
424424

425-
def stop_example(self, i: int, discarded: bool) -> None:
425+
def stop_example(self, i: int, *, discarded: bool) -> None:
426426
if self.nontrivial[i]:
427427
if self.example_stack:
428428
self.nontrivial[self.example_stack[-1]] = 1
@@ -435,7 +435,7 @@ def finish(self) -> FrozenSet[int]:
435435
trivial: FrozenSet[int] = calculated_example_property(_trivial)
436436

437437
class _parentage(ExampleProperty):
438-
def stop_example(self, i: int, discarded: bool) -> None:
438+
def stop_example(self, i: int, *, discarded: bool) -> None:
439439
if i > 0:
440440
self.result[i] = self.example_stack[-1]
441441

@@ -746,7 +746,7 @@ def conclude_test(
746746
Note that this is called after ``freeze`` has completed.
747747
"""
748748

749-
def draw_bits(self, n_bits: int, forced: bool, value: int) -> None:
749+
def draw_bits(self, n_bits: int, *, forced: bool, value: int) -> None:
750750
"""Called when ``draw_bits`` is called on on the
751751
observed ``ConjectureData``.
752752
* ``n_bits`` is the number of bits drawn.
@@ -973,14 +973,14 @@ def start_example(self, label: int) -> None:
973973
self.__example_record.start_example(label)
974974
self.labels_for_structure_stack.append({label})
975975

976-
def stop_example(self, discard: bool = False) -> None:
976+
def stop_example(self, *, discard: bool = False) -> None:
977977
if self.frozen:
978978
return
979979
if discard:
980980
self.has_discards = True
981981
self.depth -= 1
982982
assert self.depth >= -1
983-
self.__example_record.stop_example(discard)
983+
self.__example_record.stop_example(discard=discard)
984984

985985
labels_for_structure = self.labels_for_structure_stack.pop()
986986

@@ -1082,7 +1082,7 @@ def draw_bits(self, n: int, *, forced: Optional[int] = None) -> int:
10821082
buf = bytes(buf)
10831083
result = int_from_bytes(buf)
10841084

1085-
self.observer.draw_bits(n, forced is not None, result)
1085+
self.observer.draw_bits(n, forced=forced is not None, value=result)
10861086
self.__example_record.draw_bits(n, forced)
10871087

10881088
initial = self.index

0 commit comments

Comments
 (0)