hypothesis 6.135.13__py3-none-any.whl → 6.135.14__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.
@@ -687,9 +687,11 @@ def _valid_syntax_repr(strategy):
687
687
  elems.append(s)
688
688
  seen.add(repr(s))
689
689
  strategy = st.one_of(elems or st.nothing())
690
- # Trivial special case because the wrapped repr for text() is terrible.
690
+ # hardcode some special cases for nicer reprs
691
691
  if strategy == st.text().wrapped_strategy:
692
692
  return set(), "text()"
693
+ if strategy == st.from_type(type):
694
+ return set(), "from_type(type)"
693
695
  # Remove any typevars; we don't exploit them so they're just clutter here
694
696
  if (
695
697
  isinstance(strategy, LazyStrategy)
@@ -196,13 +196,17 @@ def sampled_from(
196
196
  that behaviour, use ``sampled_from(seq) if seq else nothing()``.
197
197
  """
198
198
  values = check_sample(elements, "sampled_from")
199
- try:
200
- if isinstance(elements, type) and issubclass(elements, enum.Enum):
201
- repr_ = f"sampled_from({elements.__module__}.{elements.__name__})"
202
- else:
203
- repr_ = f"sampled_from({elements!r})"
204
- except Exception: # pragma: no cover
205
- repr_ = None
199
+ force_repr = None
200
+ # check_sample converts to tuple unconditionally, but we want to preserve
201
+ # square braces for list reprs.
202
+ # This will not cover custom sequence implementations which return different
203
+ # braces (or other, more unusual things) for their reprs, but this is a tradeoff
204
+ # between repr accuracy and greedily-evaluating all sequence reprs (at great
205
+ # cost for large sequences).
206
+ force_repr_braces = ("[", "]") if isinstance(elements, list) else None
207
+ if isinstance(elements, type) and issubclass(elements, enum.Enum):
208
+ force_repr = f"sampled_from({elements.__module__}.{elements.__name__})"
209
+
206
210
  if isclass(elements) and issubclass(elements, enum.Flag):
207
211
  # Combinations of enum.Flag members (including empty) are also members. We generate these
208
212
  # dynamically, because static allocation takes O(2^n) memory. LazyStrategy is used for the
@@ -237,7 +241,7 @@ def sampled_from(
237
241
  .flatmap(lambda r: sets(sampled_from(flags), min_size=r, max_size=r))
238
242
  .map(lambda s: elements(reduce(operator.or_, s))),
239
243
  ]
240
- return LazyStrategy(one_of, args=inner, kwargs={}, force_repr=repr_)
244
+ return LazyStrategy(one_of, args=inner, kwargs={}, force_repr=force_repr)
241
245
  if not values:
242
246
  if (
243
247
  isinstance(elements, type)
@@ -253,7 +257,9 @@ def sampled_from(
253
257
  raise InvalidArgument("Cannot sample from a length-zero sequence.")
254
258
  if len(values) == 1:
255
259
  return just(values[0])
256
- return SampledFromStrategy(values, repr_)
260
+ return SampledFromStrategy(
261
+ values, force_repr=force_repr, force_repr_braces=force_repr_braces
262
+ )
257
263
 
258
264
 
259
265
  @cacheable
@@ -537,7 +537,9 @@ class SampledFromStrategy(SearchStrategy[Ex]):
537
537
  def __init__(
538
538
  self,
539
539
  elements: Sequence[Ex],
540
- repr_: Optional[str] = None,
540
+ *,
541
+ force_repr: Optional[str] = None,
542
+ force_repr_braces: Optional[tuple[str, str]] = None,
541
543
  transformations: tuple[
542
544
  tuple[Literal["filter", "map"], Callable[[Ex], Any]],
543
545
  ...,
@@ -546,13 +548,17 @@ class SampledFromStrategy(SearchStrategy[Ex]):
546
548
  super().__init__()
547
549
  self.elements = cu.check_sample(elements, "sampled_from")
548
550
  assert self.elements
549
- self.repr_ = repr_
551
+ self.force_repr = force_repr
552
+ self.force_repr_braces = force_repr_braces
550
553
  self._transformations = transformations
551
554
 
555
+ self._cached_repr: Optional[str] = None
556
+
552
557
  def map(self, pack: Callable[[Ex], T]) -> SearchStrategy[T]:
553
558
  s = type(self)(
554
559
  self.elements,
555
- repr_=self.repr_,
560
+ force_repr=self.force_repr,
561
+ force_repr_braces=self.force_repr_braces,
556
562
  transformations=(*self._transformations, ("map", pack)),
557
563
  )
558
564
  # guaranteed by the ("map", pack) transformation
@@ -561,20 +567,30 @@ class SampledFromStrategy(SearchStrategy[Ex]):
561
567
  def filter(self, condition: Callable[[Ex], Any]) -> SearchStrategy[Ex]:
562
568
  return type(self)(
563
569
  self.elements,
564
- repr_=self.repr_,
570
+ force_repr=self.force_repr,
571
+ force_repr_braces=self.force_repr_braces,
565
572
  transformations=(*self._transformations, ("filter", condition)),
566
573
  )
567
574
 
568
- def __repr__(self) -> str:
569
- return (
570
- self.repr_
571
- or "sampled_from(["
572
- + ", ".join(map(get_pretty_function_description, self.elements))
573
- + "])"
574
- ) + "".join(
575
- f".{name}({get_pretty_function_description(f)})"
576
- for name, f in self._transformations
577
- )
575
+ def __repr__(self):
576
+ if self._cached_repr is None:
577
+ rep = get_pretty_function_description
578
+ elements_s = (
579
+ ", ".join(rep(v) for v in self.elements[:512]) + ", ..."
580
+ if len(self.elements) > 512
581
+ else ", ".join(rep(v) for v in self.elements)
582
+ )
583
+ braces = self.force_repr_braces or ("(", ")")
584
+ instance_s = (
585
+ self.force_repr or f"sampled_from({braces[0]}{elements_s}{braces[1]})"
586
+ )
587
+ transforms_s = "".join(
588
+ f".{name}({get_pretty_function_description(f)})"
589
+ for name, f in self._transformations
590
+ )
591
+ repr_s = instance_s + transforms_s
592
+ self._cached_repr = repr_s
593
+ return self._cached_repr
578
594
 
579
595
  def calc_label(self) -> int:
580
596
  # strategy.label is effectively an under-approximation of structural
hypothesis/version.py CHANGED
@@ -8,5 +8,5 @@
8
8
  # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
9
  # obtain one at https://mozilla.org/MPL/2.0/.
10
10
 
11
- __version_info__ = (6, 135, 13)
11
+ __version_info__ = (6, 135, 14)
12
12
  __version__ = ".".join(map(str, __version_info__))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypothesis
3
- Version: 6.135.13
3
+ Version: 6.135.14
4
4
  Summary: A library for property-based testing
5
5
  Author-email: "David R. MacIver and Zac Hatfield-Dodds" <david@drmaciver.com>
6
6
  License-Expression: MPL-2.0
@@ -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=33U0FtVuRnY5EzIiCL50SHAT6ZPe1n2pbaohkxTF6gc,42955
16
16
  hypothesis/statistics.py,sha256=kZ5mc0fAg7gnSO6EmDo82fyz8DYhIiJ_mHe7srxOeQ0,5438
17
- hypothesis/version.py,sha256=7K66pN_oQPeh0-Pp2Mw7lPtnPjXfrOk1Iyy-Q4F3p08,499
17
+ hypothesis/version.py,sha256=uVRLrYsnZAaYwocrBVavkHP9zv5eHbqliGh3Ab5heVs,499
18
18
  hypothesis/extra/__init__.py,sha256=gx4ENVDkrzBxy5Lv3Iyfs3tvMGdWMbiHfi95B7t61CY,415
19
19
  hypothesis/extra/_array_helpers.py,sha256=PLmFckBfQpzQ4Q3dFJQqMmrbm7Qdvqxf1t9LHDCuSp0,27627
20
20
  hypothesis/extra/_patching.py,sha256=A5s5EAf81itr--w4SAFyzuecSZm4eT397jM7BvbnQXU,12385
@@ -23,7 +23,7 @@ hypothesis/extra/cli.py,sha256=HOH_BGosyUvS4yNDsWF4Dfe672tEFGT4BBPBuZamm1s,12885
23
23
  hypothesis/extra/codemods.py,sha256=i_iM5aSnrNjSZ_uNW40yShxXo7qaXuCrDHy8OznOa7o,11224
24
24
  hypothesis/extra/dateutil.py,sha256=qujQoi9apnaI5yCoupZ2XkJX0e4VAmkjycaypOMTWIQ,2295
25
25
  hypothesis/extra/dpcontracts.py,sha256=dftcHX-HeBaf8EWLitwMwFwQsSu7v9f1gv4pniOeTsA,1721
26
- hypothesis/extra/ghostwriter.py,sha256=suexNt3cbk7iGIFeAmMsSoTOmRmHXJWtEYxcisBgaxg,72684
26
+ hypothesis/extra/ghostwriter.py,sha256=Og1rAwYm2_labvytiGylTwJrXeoyfLAXmeY9r5FDbvQ,72745
27
27
  hypothesis/extra/lark.py,sha256=mInkJPG-6lXLt7GEZUs7DVrGN99ZuNRU6ZIn5ObwaWk,9892
28
28
  hypothesis/extra/numpy.py,sha256=R_hTow6-AteuGD2Xg_Ouz9vts1Dn3D75K8R2ucseYJw,51839
29
29
  hypothesis/extra/pytestplugin.py,sha256=OmbL8Nrqm6UpzxXPnfzZ4yFAqVfFGYGzZM4qxdOgJg4,752
@@ -80,7 +80,7 @@ hypothesis/strategies/__init__.py,sha256=N2r8JsCcq1yr3CD_Xg9iN9W_JfpB0kk-_Y3gh-e
80
80
  hypothesis/strategies/_internal/__init__.py,sha256=Ji2fRsYbdU66SbiFSU3kB6K6jPAYq96ZyYR8veDbAiE,620
81
81
  hypothesis/strategies/_internal/attrs.py,sha256=-DDOY_K8ogQq17PzuLaKmzP12T-sSrWPGyb6CS2B5kI,8826
82
82
  hypothesis/strategies/_internal/collections.py,sha256=5YW0DvRJOzibQrArr4HOi3Q9NEq4v44r1avnAsNt0nQ,13875
83
- hypothesis/strategies/_internal/core.py,sha256=8k2klq6x_iIZ_bhC2Fol7i0PIns4AVJ0yOC1Dw_3BZk,106690
83
+ hypothesis/strategies/_internal/core.py,sha256=tWuZghZVwhOheRSDblMWsg6uznhvWdHgurVTjCCXAIo,107115
84
84
  hypothesis/strategies/_internal/datetime.py,sha256=kjTwhgiCUouZNDWQsgwJH3MOhkUCbvj_xL2DzqYj3Rw,20072
85
85
  hypothesis/strategies/_internal/deferred.py,sha256=0dNGbjS3wsVFs8QNl_FySdV--jeLTe-DPoBL5U690_A,3684
86
86
  hypothesis/strategies/_internal/featureflags.py,sha256=sDp1fqt0vXfZ7KADwSFxyh5J3CqlM76o90I5BFohMcM,5552
@@ -94,7 +94,7 @@ hypothesis/strategies/_internal/random.py,sha256=_gSBHa0gXF4RZxjBySB43vNHsU34r8N
94
94
  hypothesis/strategies/_internal/recursive.py,sha256=BgchGM4dLo02FKQJlkNyyJlBOBf6266YlhcoQbYVVGA,3757
95
95
  hypothesis/strategies/_internal/regex.py,sha256=wGvC-S_sFO3RAajUu3hL-_5ORqsTv69CJex6QiPKI0w,21669
96
96
  hypothesis/strategies/_internal/shared.py,sha256=xoLb-wpVru5rq4Ab6L7GIo3JVl8IviWw1We8Hb4I5C8,2461
97
- hypothesis/strategies/_internal/strategies.py,sha256=kRKgpKEUSFuAk9OI4RZ4fyhsX-iKg2dkd_gYMnylfD8,46805
97
+ hypothesis/strategies/_internal/strategies.py,sha256=F91MvpD3PtozlZ_KN1lHFHoR90ORVAwYC_4LzgGOYjw,47585
98
98
  hypothesis/strategies/_internal/strings.py,sha256=UYm6d1z5c55AUYKrwJ1xnfharl81dy-q_2f0YFZbzmw,13987
99
99
  hypothesis/strategies/_internal/types.py,sha256=epJg-yW_TZZHaqZvBJhsnwi4ahDOPAyz98PRn_OaeK4,41837
100
100
  hypothesis/strategies/_internal/utils.py,sha256=4LXp6s-NV8hpBKgkW3wT3XegUUZ5vQQyv_lxFI_fGQ4,8117
@@ -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.13.dist-info/licenses/LICENSE.txt,sha256=rIkDe6xjVQZE3OjPMsZ2Xl-rncGhzpS4n4qAXzQaZ1A,17141
109
- hypothesis-6.135.13.dist-info/METADATA,sha256=bzpeanOB2or_iIHo0kEptUdSMhIscS8VcDz_22BL33Y,5638
110
- hypothesis-6.135.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
111
- hypothesis-6.135.13.dist-info/entry_points.txt,sha256=JDoUs9w1bYme7aG_eJ1cCtstRTWD71BzG8iRi-G2eHE,113
112
- hypothesis-6.135.13.dist-info/top_level.txt,sha256=ReGreaueiJ4d1I2kEiig_CLeA0sD4QCQ4qk_8kH1oDc,81
113
- hypothesis-6.135.13.dist-info/RECORD,,
108
+ hypothesis-6.135.14.dist-info/licenses/LICENSE.txt,sha256=rIkDe6xjVQZE3OjPMsZ2Xl-rncGhzpS4n4qAXzQaZ1A,17141
109
+ hypothesis-6.135.14.dist-info/METADATA,sha256=qWU8ezZvF9cOxsd6Iz4ZzzGbCAeF2bzTkJ9yaIEzZ6Y,5638
110
+ hypothesis-6.135.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
111
+ hypothesis-6.135.14.dist-info/entry_points.txt,sha256=JDoUs9w1bYme7aG_eJ1cCtstRTWD71BzG8iRi-G2eHE,113
112
+ hypothesis-6.135.14.dist-info/top_level.txt,sha256=ReGreaueiJ4d1I2kEiig_CLeA0sD4QCQ4qk_8kH1oDc,81
113
+ hypothesis-6.135.14.dist-info/RECORD,,