Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RELEASE_TYPE: patch

Clean up an internal helper.
17 changes: 1 addition & 16 deletions hypothesis-python/src/hypothesis/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import datetime
import inspect
import os
import warnings
from collections.abc import Collection, Generator, Sequence
from enum import Enum, EnumMeta, unique
from functools import total_ordering
Expand All @@ -31,13 +30,13 @@
)

from hypothesis.errors import (
HypothesisDeprecationWarning,
InvalidArgument,
)
from hypothesis.internal.conjecture.providers import AVAILABLE_PROVIDERS
from hypothesis.internal.reflection import get_pretty_function_description
from hypothesis.internal.validation import check_type, try_convert
from hypothesis.utils.conventions import not_set
from hypothesis.utils.deprecation import note_deprecation
from hypothesis.utils.dynamicvariables import DynamicVariable

if TYPE_CHECKING:
Expand Down Expand Up @@ -1191,20 +1190,6 @@ def local_settings(s: settings) -> Generator[settings, None, None]:
yield s


def note_deprecation(
message: str, *, since: str, has_codemod: bool, stacklevel: int = 0
) -> None:
if since != "RELEASEDAY":
date = datetime.date.fromisoformat(since)
assert datetime.date(2021, 1, 1) <= date
if has_codemod:
message += (
"\n The `hypothesis codemod` command-line tool can automatically "
"refactor your code to fix this warning."
)
warnings.warn(HypothesisDeprecationWarning(message), stacklevel=2 + stacklevel)


default = settings(
max_examples=100,
derandomize=False,
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
from weakref import WeakKeyDictionary

from hypothesis import Verbosity, settings
from hypothesis._settings import note_deprecation
from hypothesis.errors import InvalidArgument, UnsatisfiedAssumption
from hypothesis.internal.compat import BaseExceptionGroup
from hypothesis.internal.conjecture.data import ConjectureData
from hypothesis.internal.observability import observability_enabled
from hypothesis.internal.reflection import get_pretty_function_description
from hypothesis.internal.validation import check_type
from hypothesis.reporting import report, verbose_report
from hypothesis.utils.deprecation import note_deprecation
from hypothesis.utils.dynamicvariables import DynamicVariable
from hypothesis.vendor.pretty import IDKey, PrettyPrintFunction, pretty

Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
from urllib.request import Request, urlopen
from zipfile import BadZipFile, ZipFile

from hypothesis._settings import note_deprecation
from hypothesis.configuration import storage_directory
from hypothesis.errors import HypothesisException, HypothesisWarning
from hypothesis.internal.conjecture.choice import ChoiceT
from hypothesis.utils.conventions import UniqueIdentifier, not_set
from hypothesis.utils.deprecation import note_deprecation

__all__ = [
"DirectoryBasedExampleDatabase",
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ class Frozen(HypothesisException):

def __getattr__(name: str) -> Any:
if name == "MultipleFailures":
from hypothesis._settings import note_deprecation
from hypothesis.internal.compat import BaseExceptionGroup
from hypothesis.utils.deprecation import note_deprecation

note_deprecation(
"MultipleFailures is deprecated; use the builtin `BaseExceptionGroup` type "
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import numpy as np

from hypothesis import strategies as st
from hypothesis._settings import note_deprecation
from hypothesis.errors import HypothesisException, InvalidArgument
from hypothesis.extra._array_helpers import (
_BIE,
Expand Down Expand Up @@ -60,6 +59,7 @@
check_strategy,
)
from hypothesis.strategies._internal.utils import defines_strategy
from hypothesis.utils.deprecation import note_deprecation


def _try_import(mod_name: str, attr_name: str) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/pandas/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import pandas

from hypothesis import strategies as st
from hypothesis._settings import note_deprecation
from hypothesis.control import reject
from hypothesis.errors import InvalidArgument
from hypothesis.extra import numpy as npst
Expand All @@ -33,6 +32,7 @@
)
from hypothesis.strategies._internal.strategies import Ex, check_strategy
from hypothesis.strategies._internal.utils import cacheable, defines_strategy
from hypothesis.utils.deprecation import note_deprecation

try:
from pandas.core.arrays.integer import IntegerDtype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from hypothesis.internal.observability import PredicateCounts
from hypothesis.reporting import debug_report
from hypothesis.utils.conventions import not_set
from hypothesis.utils.deprecation import note_deprecation
from hypothesis.utils.threading import ThreadLocal

if TYPE_CHECKING:
Expand All @@ -81,7 +82,6 @@

def __getattr__(name: str) -> Any:
if name == "AVAILABLE_PROVIDERS":
from hypothesis._settings import note_deprecation
from hypothesis.internal.conjecture.providers import AVAILABLE_PROVIDERS

note_deprecation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing import Literal, NoReturn, cast

from hypothesis import HealthCheck, Phase, Verbosity, settings as Settings
from hypothesis._settings import local_settings, note_deprecation
from hypothesis._settings import local_settings
from hypothesis.database import ExampleDatabase, choices_from_bytes, choices_to_bytes
from hypothesis.errors import (
BackendCannotProceed,
Expand Down Expand Up @@ -70,6 +70,7 @@
from hypothesis.internal.healthcheck import fail_health_check
from hypothesis.internal.observability import Observation, with_observability_callback
from hypothesis.reporting import base_report, report, verbose_report
from hypothesis.utils.deprecation import note_deprecation

# In most cases, the following constants are all Final. However, we do allow users
# to monkeypatch all of these variables, which means we cannot annotate them as
Expand Down
3 changes: 1 addition & 2 deletions hypothesis-python/src/hypothesis/internal/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from hypothesis.internal.escalation import InterestingOrigin
from hypothesis.internal.floats import float_to_int
from hypothesis.internal.intervalsets import IntervalSet
from hypothesis.utils.deprecation import note_deprecation

if TYPE_CHECKING:
from hypothesis.internal.conjecture.data import ConjectureData, Spans, Status
Expand Down Expand Up @@ -355,8 +356,6 @@ def __bool__(self):
return bool(_callbacks)

def _note_deprecation(self):
from hypothesis._settings import note_deprecation

note_deprecation(
"hypothesis.internal.observability.TESTCASE_CALLBACKS is deprecated. "
"Replace TESTCASE_CALLBACKS.append with add_observability_callback, "
Expand Down
8 changes: 2 additions & 6 deletions hypothesis-python/src/hypothesis/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
from unittest import TestCase

from hypothesis import strategies as st
from hypothesis._settings import (
HealthCheck,
Verbosity,
note_deprecation,
settings as Settings,
)
from hypothesis._settings import HealthCheck, Verbosity, settings as Settings
from hypothesis.control import _current_build_context, current_build_context
from hypothesis.core import TestFunc, given
from hypothesis.errors import (
Expand Down Expand Up @@ -62,6 +57,7 @@
SearchStrategy,
check_strategy,
)
from hypothesis.utils.deprecation import note_deprecation
from hypothesis.vendor.pretty import RepresentationPrinter

T = TypeVar("T")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
)
from uuid import UUID

from hypothesis._settings import note_deprecation
from hypothesis.control import (
cleanup,
current_build_context,
Expand Down Expand Up @@ -138,6 +137,7 @@
)
from hypothesis.strategies._internal.utils import cacheable, defines_strategy
from hypothesis.utils.conventions import not_set
from hypothesis.utils.deprecation import note_deprecation
from hypothesis.vendor.pretty import RepresentationPrinter


Expand Down
28 changes: 28 additions & 0 deletions hypothesis-python/src/hypothesis/utils/deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is part of Hypothesis, which may be found at
# https://github.com/HypothesisWorks/hypothesis/
#
# Copyright the Hypothesis Authors.
# Individual contributors are listed in AUTHORS.rst and the git log.
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.

import datetime
import warnings

from hypothesis.errors import HypothesisDeprecationWarning


def note_deprecation(
message: str, *, since: str, has_codemod: bool, stacklevel: int = 0
) -> None:
if since != "RELEASEDAY":
date = datetime.date.fromisoformat(since)
assert datetime.date(2021, 1, 1) <= date
if has_codemod:
message += (
"\n The `hypothesis codemod` command-line tool can automatically "
"refactor your code to fix this warning."
)
warnings.warn(HypothesisDeprecationWarning(message), stacklevel=2 + stacklevel)
26 changes: 6 additions & 20 deletions hypothesis-python/tests/cover/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
Verbosity,
default_variable,
local_settings,
note_deprecation,
settings,
)
from hypothesis.database import InMemoryExampleDatabase
Expand All @@ -36,6 +35,7 @@
)
from hypothesis.stateful import RuleBasedStateMachine, rule
from hypothesis.utils.conventions import not_set
from hypothesis.utils.deprecation import note_deprecation

from tests.common.utils import (
checks_deprecated_behaviour,
Expand Down Expand Up @@ -381,22 +381,6 @@ def test_deadline_given_valid_timedelta():
assert x.microseconds == 30000


@pytest.mark.parametrize(
"x",
[
0,
-0.7,
-1,
86400000000000000.2,
datetime.timedelta(microseconds=-1),
datetime.timedelta(0),
],
)
def test_invalid_deadline(x):
with pytest.raises(InvalidArgument):
settings(deadline=x)


@pytest.mark.parametrize("value", ["always"])
def test_can_not_set_print_blob_to_non_print_settings(value):
with pytest.raises(InvalidArgument):
Expand Down Expand Up @@ -467,6 +451,10 @@ def test_derandomise_with_explicit_database_is_invalid():
{"stateful_step_count": 2.5},
{"deadline": -1},
{"deadline": 0},
{"deadline": -0.7},
{"deadline": 86400000000000000.2},
{"deadline": datetime.timedelta(microseconds=-1)},
{"deadline": datetime.timedelta(0)},
{"deadline": True},
{"deadline": False},
{"backend": "nonexistent_backend"},
Expand All @@ -489,11 +477,9 @@ def __repr__(self):

not_settings = NotSettings()

with pytest.raises(InvalidArgument) as excinfo:
with pytest.raises(InvalidArgument, match=r"parent=\(not settings repr\)"):
settings(not_settings)

assert "parent=(not settings repr)" in str(excinfo.value)


def test_default_settings_do_not_use_ci():
assert settings.get_profile("default").suppress_health_check == ()
Expand Down