hypothesis 6.135.3__py3-none-any.whl → 6.135.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hypothesis/core.py +14 -1
- hypothesis/internal/conjecture/providers.py +1 -1
- hypothesis/internal/constants_ast.py +36 -8
- hypothesis/version.py +1 -1
- {hypothesis-6.135.3.dist-info → hypothesis-6.135.5.dist-info}/METADATA +1 -1
- {hypothesis-6.135.3.dist-info → hypothesis-6.135.5.dist-info}/RECORD +10 -10
- {hypothesis-6.135.3.dist-info → hypothesis-6.135.5.dist-info}/WHEEL +0 -0
- {hypothesis-6.135.3.dist-info → hypothesis-6.135.5.dist-info}/entry_points.txt +0 -0
- {hypothesis-6.135.3.dist-info → hypothesis-6.135.5.dist-info}/licenses/LICENSE.txt +0 -0
- {hypothesis-6.135.3.dist-info → hypothesis-6.135.5.dist-info}/top_level.txt +0 -0
hypothesis/core.py
CHANGED
@@ -1781,7 +1781,20 @@ def given(
|
|
1781
1781
|
if inspect.isclass(test):
|
1782
1782
|
# Provide a meaningful error to users, instead of exceptions from
|
1783
1783
|
# internals that assume we're dealing with a function.
|
1784
|
-
raise InvalidArgument("@given cannot be applied to a class
|
1784
|
+
raise InvalidArgument("@given cannot be applied to a class")
|
1785
|
+
|
1786
|
+
if (
|
1787
|
+
"_pytest" in sys.modules
|
1788
|
+
and (
|
1789
|
+
tuple(map(int, sys.modules["_pytest"].__version__.split(".")[:2]))
|
1790
|
+
>= (8, 4)
|
1791
|
+
)
|
1792
|
+
and isinstance(
|
1793
|
+
test, sys.modules["_pytest"].fixtures.FixtureFunctionDefinition
|
1794
|
+
)
|
1795
|
+
): # pragma: no cover # covered by pytest/test_fixtures, but not by cover/
|
1796
|
+
raise InvalidArgument("@given cannot be applied to a pytest fixture")
|
1797
|
+
|
1785
1798
|
given_arguments = tuple(_given_arguments)
|
1786
1799
|
given_kwargs = dict(_given_kwargs)
|
1787
1800
|
|
@@ -568,7 +568,7 @@ class PrimitiveProvider(abc.ABC):
|
|
568
568
|
.. important::
|
569
569
|
|
570
570
|
For |PrimitiveProvider.on_observation| to be called by Hypothesis,
|
571
|
-
|PrimitiveProvider.add_observability_callback| must be set to ``True
|
571
|
+
|PrimitiveProvider.add_observability_callback| must be set to ``True``.
|
572
572
|
|
573
573
|
|PrimitiveProvider.on_observation| is explicitly opt-in, as enabling
|
574
574
|
observability might increase runtime or memory usage.
|
@@ -98,12 +98,24 @@ class Constants:
|
|
98
98
|
)
|
99
99
|
|
100
100
|
|
101
|
+
class TooManyConstants(Exception):
|
102
|
+
# a control flow exception which we raise in ConstantsVisitor when the
|
103
|
+
# number of constants in a module gets too large.
|
104
|
+
pass
|
105
|
+
|
106
|
+
|
101
107
|
class ConstantVisitor(NodeVisitor):
|
102
|
-
|
108
|
+
CONSTANTS_LIMIT: int = 1024
|
109
|
+
|
110
|
+
def __init__(self, *, limit: bool):
|
103
111
|
super().__init__()
|
104
112
|
self.constants = Constants()
|
113
|
+
self.limit = limit
|
105
114
|
|
106
115
|
def _add_constant(self, value: object) -> None:
|
116
|
+
if self.limit and len(self.constants) >= self.CONSTANTS_LIMIT:
|
117
|
+
raise TooManyConstants
|
118
|
+
|
107
119
|
if isinstance(value, str) and (
|
108
120
|
value.isspace()
|
109
121
|
or value == ""
|
@@ -166,15 +178,22 @@ class ConstantVisitor(NodeVisitor):
|
|
166
178
|
self.generic_visit(node)
|
167
179
|
|
168
180
|
|
169
|
-
def _constants_from_source(source: Union[str, bytes]) -> Constants:
|
181
|
+
def _constants_from_source(source: Union[str, bytes], *, limit: bool) -> Constants:
|
170
182
|
tree = ast.parse(source)
|
171
|
-
visitor = ConstantVisitor()
|
172
|
-
|
183
|
+
visitor = ConstantVisitor(limit=limit)
|
184
|
+
|
185
|
+
try:
|
186
|
+
visitor.visit(tree)
|
187
|
+
except TooManyConstants:
|
188
|
+
# in the case of an incomplete collection, return nothing, to avoid
|
189
|
+
# muddying caches etc.
|
190
|
+
return Constants()
|
191
|
+
|
173
192
|
return visitor.constants
|
174
193
|
|
175
194
|
|
176
195
|
@lru_cache(4096)
|
177
|
-
def constants_from_module(module: ModuleType) -> Constants:
|
196
|
+
def constants_from_module(module: ModuleType, *, limit: bool = True) -> Constants:
|
178
197
|
try:
|
179
198
|
module_file = inspect.getsourcefile(module)
|
180
199
|
# use type: ignore because we know this might error
|
@@ -182,17 +201,26 @@ def constants_from_module(module: ModuleType) -> Constants:
|
|
182
201
|
except Exception:
|
183
202
|
return Constants()
|
184
203
|
|
204
|
+
if limit and len(source_bytes) > 512 * 1024:
|
205
|
+
# Skip files over 512kb. For reference, the largest source file
|
206
|
+
# in Hypothesis is strategies/_internal/core.py at 107kb at time
|
207
|
+
# of writing.
|
208
|
+
return Constants()
|
209
|
+
|
185
210
|
source_hash = hashlib.sha1(source_bytes).hexdigest()[:16]
|
186
|
-
|
211
|
+
# separate cache files for each limit param. see discussion in pull/4398
|
212
|
+
cache_p = storage_directory("constants") / (
|
213
|
+
source_hash + ("" if limit else "_nolimit")
|
214
|
+
)
|
187
215
|
try:
|
188
|
-
return _constants_from_source(cache_p.read_bytes())
|
216
|
+
return _constants_from_source(cache_p.read_bytes(), limit=limit)
|
189
217
|
except Exception:
|
190
218
|
# if the cached location doesn't exist, or it does exist but there was
|
191
219
|
# a problem reading it, fall back to standard computation of the constants
|
192
220
|
pass
|
193
221
|
|
194
222
|
try:
|
195
|
-
constants = _constants_from_source(source_bytes)
|
223
|
+
constants = _constants_from_source(source_bytes, limit=limit)
|
196
224
|
except Exception:
|
197
225
|
# A bunch of things can go wrong here.
|
198
226
|
# * ast.parse may fail on the source code
|
hypothesis/version.py
CHANGED
@@ -5,7 +5,7 @@ hypothesis/__init__.py,sha256=-l2jKA8BwEWYTJoebvxmhJjA3M_K9qsMRu5CCNVCDFs,1624
|
|
5
5
|
hypothesis/_settings.py,sha256=FGEckgd43ifGBrGcP8pN0YiVu74ZZl2IqghgUZBPUPI,39049
|
6
6
|
hypothesis/configuration.py,sha256=ruHxaoUFm9_gjyFhloszHF8wt-_yW8FQtWfMXFLwdzc,4341
|
7
7
|
hypothesis/control.py,sha256=6zyn0hDDOt5FugCpD2vw1UJFn3uYwd7lpYqMLoHpOgQ,12625
|
8
|
-
hypothesis/core.py,sha256=
|
8
|
+
hypothesis/core.py,sha256=SNleVqFMjWOtrPYByAbl0XBqkTnHKq12-fKbK0kWEQw,92576
|
9
9
|
hypothesis/database.py,sha256=kn4BIwA-avXJSQoNq0aNpFehaO54K-ltpXf3sRKv9rA,46785
|
10
10
|
hypothesis/entry_points.py,sha256=aY9iTAiu1GaLljqqXFcMBgipZQ60RBOwwvPVmEr1lQE,1440
|
11
11
|
hypothesis/errors.py,sha256=fci2Xe3kUIEBZ92361vot2f7IRjtfEn1aI1Bdf8vfRU,10048
|
@@ -14,7 +14,7 @@ hypothesis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
hypothesis/reporting.py,sha256=f-jhl1JfAi5_tG8dsUd2qDjGcPdvxEzfF6hXmpTFQ1g,1761
|
15
15
|
hypothesis/stateful.py,sha256=vQ8wDO7YW-8nGlBGLfR9ariwmRCS9jxJy-Ky3swXjDE,42861
|
16
16
|
hypothesis/statistics.py,sha256=kZ5mc0fAg7gnSO6EmDo82fyz8DYhIiJ_mHe7srxOeQ0,5438
|
17
|
-
hypothesis/version.py,sha256=
|
17
|
+
hypothesis/version.py,sha256=1KUUVcYo3Qi08mwoUMHkDMvLESX7R48nZxsi3ewaNpY,498
|
18
18
|
hypothesis/extra/__init__.py,sha256=gx4ENVDkrzBxy5Lv3Iyfs3tvMGdWMbiHfi95B7t61CY,415
|
19
19
|
hypothesis/extra/_array_helpers.py,sha256=Sdr_lUQPBCXOhtY2TQpuXoiXErOZomNVuFU5FZWZLXQ,27624
|
20
20
|
hypothesis/extra/_patching.py,sha256=pLgtFBgwDEotw6Pu8ZfJbkE5Qk5F1H3IH5EPUo0Ngm4,10869
|
@@ -39,7 +39,7 @@ hypothesis/internal/cache.py,sha256=5GJ92S7HNjefuiOOSUchp3IYw1XxLVRmYoFHEoL7eVk,
|
|
39
39
|
hypothesis/internal/cathetus.py,sha256=q6t16mT2jzlJmBddhRlqC2wg_w7FggVDRAVkzs04W-U,2258
|
40
40
|
hypothesis/internal/charmap.py,sha256=dIsRCxa6r1r-rF_NUy04Z-afFa2b6fCFEjWTMYsAgXY,11781
|
41
41
|
hypothesis/internal/compat.py,sha256=CexhnEVndODX3E-iJmBzt_svqLmADF_6vWkd7lXLRQI,10970
|
42
|
-
hypothesis/internal/constants_ast.py,sha256=
|
42
|
+
hypothesis/internal/constants_ast.py,sha256=to4zxaUpA4JU5iPXy2pOb38dWG_tibu6UZkd2Vrq-fA,10091
|
43
43
|
hypothesis/internal/coverage.py,sha256=u2ALnaYgwd2jSkZkA5aQYA1uMnk7gwaasMJbq_l3iIg,3380
|
44
44
|
hypothesis/internal/detection.py,sha256=v_zf0GYsnfJKQMNw78qYv61Dh-YaXXfgqKpVIOsBvfw,1228
|
45
45
|
hypothesis/internal/entropy.py,sha256=wgNeddIM0I3SD1yydz12Lsop6Di5vsle4e9u5fWAxIs,8014
|
@@ -62,7 +62,7 @@ hypothesis/internal/conjecture/junkdrawer.py,sha256=82sWQk3pdYWvdA0Xp2gFwAX0tdOx
|
|
62
62
|
hypothesis/internal/conjecture/optimiser.py,sha256=DI_1IZ3ncmqGYkxzldSTFWqMpLND8zf6rIhAVJlqekk,8902
|
63
63
|
hypothesis/internal/conjecture/pareto.py,sha256=WPWvMOFR5HDNZsIoBrWkdNQoRfKdemL5kld2LkzRkfY,15347
|
64
64
|
hypothesis/internal/conjecture/provider_conformance.py,sha256=uj5qJzf1rorX-2SZJ9tZluT1HY3LwZEo8RDXqwEP-XI,16329
|
65
|
-
hypothesis/internal/conjecture/providers.py,sha256=
|
65
|
+
hypothesis/internal/conjecture/providers.py,sha256=npX6jUNiOsFe0Q6HCwGcNNMCufq6coQi0hBfUO8e1Fo,42642
|
66
66
|
hypothesis/internal/conjecture/shrinker.py,sha256=VXDuD-1aUwBbB2j3xffaaVje3G2YxUd1P9ukeMq0PPw,75476
|
67
67
|
hypothesis/internal/conjecture/utils.py,sha256=hQNW_50qTPsqJjdSA7rvqBG2SfDQ0rsJJtnKNYXvBX0,13694
|
68
68
|
hypothesis/internal/conjecture/dfa/__init__.py,sha256=s6RdUNlNd9EiTowj5PFDxPEOjsDw3xemp_c7Y_vjzq0,23904
|
@@ -105,9 +105,9 @@ hypothesis/utils/terminal.py,sha256=IxGYDGaE4R3b_vMfz5buWbN18XH5qVP4IxqAgNAU5as,
|
|
105
105
|
hypothesis/vendor/__init__.py,sha256=gx4ENVDkrzBxy5Lv3Iyfs3tvMGdWMbiHfi95B7t61CY,415
|
106
106
|
hypothesis/vendor/pretty.py,sha256=WEZC-UV-QQgCjUf2Iz1WWaWnbgT7Hc3s-GWEVxq-Qz0,36114
|
107
107
|
hypothesis/vendor/tlds-alpha-by-domain.txt,sha256=W9hYvpu2BMmNgE-SfPp8-GTzEVjw0HJUviqlvHwpZu8,9588
|
108
|
-
hypothesis-6.135.
|
109
|
-
hypothesis-6.135.
|
110
|
-
hypothesis-6.135.
|
111
|
-
hypothesis-6.135.
|
112
|
-
hypothesis-6.135.
|
113
|
-
hypothesis-6.135.
|
108
|
+
hypothesis-6.135.5.dist-info/licenses/LICENSE.txt,sha256=rIkDe6xjVQZE3OjPMsZ2Xl-rncGhzpS4n4qAXzQaZ1A,17141
|
109
|
+
hypothesis-6.135.5.dist-info/METADATA,sha256=exQ0yKMoxXfAWzAPFiFyhGCQuuQuzPWpRA7coWSaOwg,5637
|
110
|
+
hypothesis-6.135.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
111
|
+
hypothesis-6.135.5.dist-info/entry_points.txt,sha256=JDoUs9w1bYme7aG_eJ1cCtstRTWD71BzG8iRi-G2eHE,113
|
112
|
+
hypothesis-6.135.5.dist-info/top_level.txt,sha256=ReGreaueiJ4d1I2kEiig_CLeA0sD4QCQ4qk_8kH1oDc,81
|
113
|
+
hypothesis-6.135.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|