|
20 | 20 | from datetime import timedelta |
21 | 21 | from enum import Enum |
22 | 22 | from random import Random, getrandbits |
23 | | -from typing import Callable, Final, Literal, NoReturn, Optional, Union, cast |
| 23 | +from typing import Callable, Literal, NoReturn, Optional, Union, cast |
24 | 24 |
|
25 | 25 | from hypothesis import HealthCheck, Phase, Verbosity, settings as Settings |
26 | 26 | from hypothesis._settings import local_settings, note_deprecation |
|
71 | 71 | from hypothesis.internal.observability import Observation, with_observability_callback |
72 | 72 | from hypothesis.reporting import base_report, report |
73 | 73 |
|
| 74 | +# In most cases, the following constants are all Final. However, we do allow users |
| 75 | +# to monkeypatch all of these variables, which means we cannot annotate them as |
| 76 | +# Final or mypyc will inline them and render monkeypatching useless. |
| 77 | + |
74 | 78 | #: The maximum number of times the shrinker will reduce the complexity of a failing |
75 | 79 | #: input before giving up. This avoids falling down a trap of exponential (or worse) |
76 | 80 | #: complexity, where the shrinker appears to be making progress but will take a |
77 | 81 | #: substantially long time to finish completely. |
78 | | -MAX_SHRINKS: Final[int] = 500 |
| 82 | +MAX_SHRINKS: int = 500 |
79 | 83 |
|
80 | 84 | # If the shrinking phase takes more than five minutes, abort it early and print |
81 | 85 | # a warning. Many CI systems will kill a build after around ten minutes with |
|
87 | 91 | #: for before giving up. This is across all shrinks for the same failure, so even |
88 | 92 | #: if the shrinker successfully reduces the complexity of a single failure several |
89 | 93 | #: times, it will stop when it hits |MAX_SHRINKING_SECONDS| of total time taken. |
90 | | -MAX_SHRINKING_SECONDS: Final[int] = 300 |
| 94 | +MAX_SHRINKING_SECONDS: int = 300 |
91 | 95 |
|
92 | 96 | #: The maximum amount of entropy a single test case can use before giving up |
93 | 97 | #: while making random choices during input generation. |
94 | 98 | #: |
95 | 99 | #: The "unit" of one |BUFFER_SIZE| does not have any defined semantics, and you |
96 | 100 | #: should not rely on it, except that a linear increase |BUFFER_SIZE| will linearly |
97 | 101 | #: increase the amount of entropy a test case can use during generation. |
98 | | -BUFFER_SIZE: Final[int] = 8 * 1024 |
99 | | -CACHE_SIZE: Final[int] = 10000 |
100 | | -MIN_TEST_CALLS: Final[int] = 10 |
| 102 | +BUFFER_SIZE: int = 8 * 1024 |
| 103 | +CACHE_SIZE: int = 10000 |
| 104 | +MIN_TEST_CALLS: int = 10 |
101 | 105 |
|
102 | 106 |
|
103 | 107 | def shortlex(s): |
@@ -166,8 +170,8 @@ class RunIsComplete(Exception): |
166 | 170 |
|
167 | 171 |
|
168 | 172 | def _get_provider(backend: str) -> Union[type, PrimitiveProvider]: |
169 | | - mname, cname = AVAILABLE_PROVIDERS[backend].rsplit(".", 1) |
170 | | - provider_cls = getattr(importlib.import_module(mname), cname) |
| 173 | + module_name, class_name = AVAILABLE_PROVIDERS[backend].rsplit(".", 1) |
| 174 | + provider_cls = getattr(importlib.import_module(module_name), class_name) |
171 | 175 | if provider_cls.lifetime == "test_function": |
172 | 176 | return provider_cls(None) |
173 | 177 | elif provider_cls.lifetime == "test_case": |
|
0 commit comments