Skip to content

Commit

Permalink
Merge pull request #3507 from HypothesisWorks/create-pull-request/patch
Browse files Browse the repository at this point in the history
Update pinned dependencies
  • Loading branch information
Zac-HD committed Nov 14, 2022
2 parents db48c3b + b4a2eb1 commit 1b2239b
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 35 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch updates some internal type annotations and fixes a formatting bug in the
:obj:`~hypothesis.Phase.explain` phase reporting.
10 changes: 7 additions & 3 deletions hypothesis-python/src/hypothesis/extra/pandas/impl.py
Expand Up @@ -88,6 +88,11 @@ def elements_and_dtype(elements, dtype, source=None):
has_codemod=False,
)

if isinstance(dtype, st.SearchStrategy):
raise InvalidArgument(
f"Passed dtype={dtype!r} is a strategy, but we require a concrete dtype "
"here. See https://stackoverflow.com/q/74355937 for workaround patterns."
)
dtype = try_convert(np.dtype, dtype, "dtype")

if elements is None:
Expand Down Expand Up @@ -532,9 +537,8 @@ def row():
hash(c.name)
except TypeError:
raise InvalidArgument(
"Column names must be hashable, but columns[%d].name was "
"%r of type %s, which cannot be hashed."
% (i, c.name, type(c.name).__name__)
f"Column names must be hashable, but columns[{i}].name was "
f"{c.name!r} of type {type(c.name).__name__}, which cannot be hashed."
) from None

if c.name in column_names:
Expand Down
Expand Up @@ -142,7 +142,7 @@ def step(


class TreeNode:
def __init__(self):
def __init__(self) -> None:
self.children: Dict[int, TreeNode] = defaultdict(TreeNode)
self.live_child_count: "Optional[int]" = None
self.n: "Optional[int]" = None
Expand Down
14 changes: 7 additions & 7 deletions hypothesis-python/src/hypothesis/internal/conjecture/data.py
Expand Up @@ -400,10 +400,10 @@ def ends(self) -> IntList:
return self.starts_and_ends[1]

class _discarded(ExampleProperty):
def begin(self):
self.result: "Set[int]" = set()
def begin(self) -> None:
self.result: "Set[int]" = set() # type: ignore # IntList in parent class

def finish(self):
def finish(self) -> FrozenSet[int]:
return frozenset(self.result)

def stop_example(self, i: int, discarded: bool) -> None:
Expand All @@ -413,9 +413,9 @@ def stop_example(self, i: int, discarded: bool) -> None:
discarded: FrozenSet[int] = calculated_example_property(_discarded)

class _trivial(ExampleProperty):
def begin(self):
def begin(self) -> None:
self.nontrivial = IntList.of_length(len(self.examples))
self.result: "Set[int]" = set()
self.result: "Set[int]" = set() # type: ignore # IntList in parent class

def block(self, i: int) -> None:
if not self.examples.blocks.trivial(i):
Expand All @@ -428,7 +428,7 @@ def stop_example(self, i: int, discarded: bool) -> None:
else:
self.result.add(i)

def finish(self):
def finish(self) -> FrozenSet[int]:
return frozenset(self.result)

trivial: FrozenSet[int] = calculated_example_property(_trivial)
Expand Down Expand Up @@ -456,7 +456,7 @@ def start_example(self, i: int, label_index: int) -> None:
label_indices: IntList = calculated_example_property(_label_indices)

class _mutator_groups(ExampleProperty):
def begin(self):
def begin(self) -> None:
self.groups: "Dict[Tuple[int, int], List[int]]" = defaultdict(list)

def start_example(self, i: int, label_index: int) -> None:
Expand Down
4 changes: 2 additions & 2 deletions hypothesis-python/src/hypothesis/internal/conjecture/utils.py
Expand Up @@ -320,8 +320,8 @@ def __init__(self, weights: Sequence[float]):

num_type = type(total)

zero = num_type(0)
one = num_type(1)
zero = num_type(0) # type: ignore
one = num_type(1) # type: ignore

small: "List[int]" = []
large: "List[int]" = []
Expand Down
5 changes: 4 additions & 1 deletion hypothesis-python/src/hypothesis/internal/entropy.py
Expand Up @@ -12,6 +12,7 @@
import random
import sys
from itertools import count
from typing import Callable, Hashable, Tuple
from weakref import WeakValueDictionary

import hypothesis.core
Expand Down Expand Up @@ -58,7 +59,9 @@ def register_random(r: random.Random) -> None:
RANDOMS_TO_MANAGE[next(_RKEY)] = r


def get_seeder_and_restorer(seed=0):
def get_seeder_and_restorer(
seed: Hashable = 0,
) -> Tuple[Callable[[], None], Callable[[], None]]:
"""Return a pair of functions which respectively seed all and restore
the state of all registered PRNGs.
Expand Down
8 changes: 2 additions & 6 deletions hypothesis-python/src/hypothesis/internal/scrutineer.py
Expand Up @@ -11,7 +11,6 @@
import sys
from collections import defaultdict
from functools import lru_cache, reduce
from itertools import groupby
from os import sep
from pathlib import Path

Expand Down Expand Up @@ -118,10 +117,7 @@ def get_explaining_locations(traces):
def make_report(explanations, cap_lines_at=5):
report = defaultdict(list)
for origin, locations in explanations.items():
report_lines = [
" {}:{}".format(k, ", ".join(map(str, sorted(l for _, l in v))))
for k, v in groupby(locations, lambda kv: kv[0])
]
report_lines = [f" {fname}:{lineno}" for fname, lineno in locations]
report_lines.sort(key=lambda line: (line.startswith(LIB_DIR), line))
if len(report_lines) > cap_lines_at + 1:
msg = " (and {} more with settings.verbosity >= verbose)"
Expand All @@ -136,5 +132,5 @@ def explanatory_lines(traces, settings):
return defaultdict(list)
# Return human-readable report lines summarising the traces
explanations = get_explaining_locations(traces)
max_lines = 5 if settings.verbosity <= Verbosity.normal else 100
max_lines = 5 if settings.verbosity <= Verbosity.normal else float("inf")
return make_report(explanations, cap_lines_at=max_lines)
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/stateful.py
Expand Up @@ -249,7 +249,7 @@ class RuleBasedStateMachine(metaclass=StateMachineMeta):
_invariants_per_class: Dict[type, List[classmethod]] = {}
_initializers_per_class: Dict[type, List[classmethod]] = {}

def __init__(self):
def __init__(self) -> None:
if not self.rules():
raise InvalidDefinition(f"Type {type(self).__name__} defines no rules")
self.bundles: Dict[str, list] = {}
Expand Down
Expand Up @@ -1113,7 +1113,7 @@ def as_strategy(strat_or_callable, thing, final=True):
pass
if (
hasattr(typing, "_TypedDictMeta")
and type(thing) is typing._TypedDictMeta # type: ignore
and type(thing) is typing._TypedDictMeta
or hasattr(types.typing_extensions, "_TypedDictMeta") # type: ignore
and type(thing) is types.typing_extensions._TypedDictMeta # type: ignore
): # pragma: no cover
Expand Down
1 change: 1 addition & 0 deletions hypothesis-python/tests/pandas/test_argument_validation.py
Expand Up @@ -65,6 +65,7 @@
e(pdst.indexes, elements="not a strategy"),
e(pdst.indexes, elements=st.text(), dtype=float),
e(pdst.indexes, elements=st.none(), dtype=int),
e(pdst.indexes, elements=st.integers(0, 10), dtype=st.sampled_from([int, float])),
e(pdst.indexes, dtype=int, max_size=0, min_size=1),
e(pdst.indexes, dtype=int, unique="true"),
e(pdst.indexes, dtype=int, min_size="0"),
Expand Down
6 changes: 3 additions & 3 deletions requirements/coverage.txt
Expand Up @@ -30,13 +30,13 @@ exceptiongroup==1.0.1 ; python_version < "3.11"
# pytest
execnet==1.9.0
# via pytest-xdist
fakeredis==1.10.0
fakeredis==1.10.1
# via -r requirements/coverage.in
iniconfig==1.1.1
# via pytest
lark-parser==0.12.0
# via -r requirements/coverage.in
libcst==0.4.7
libcst==0.4.9
# via -r requirements/coverage.in
mypy-extensions==0.4.3
# via
Expand All @@ -56,7 +56,7 @@ pathspec==0.10.1
# via black
pexpect==4.8.0
# via -r requirements/test.in
platformdirs==2.5.2
platformdirs==2.5.3
# via black
pluggy==1.0.0
# via pytest
Expand Down
20 changes: 10 additions & 10 deletions requirements/tools.txt
Expand Up @@ -155,7 +155,7 @@ keyring==23.11.0
# via twine
lark-parser==0.12.0
# via -r requirements/tools.in
libcst==0.4.7
libcst==0.4.9
# via
# -r requirements/tools.in
# shed
Expand All @@ -167,7 +167,7 @@ mccabe==0.7.0
# via flake8
more-itertools==9.0.0
# via jaraco-classes
mypy==0.982
mypy==0.990
# via -r requirements/tools.in
mypy-extensions==0.4.3
# via
Expand Down Expand Up @@ -198,7 +198,7 @@ pip-tools==6.9.0
# via -r requirements/tools.in
pkginfo==1.8.3
# via twine
platformdirs==2.5.2
platformdirs==2.5.3
# via
# black
# virtualenv
Expand Down Expand Up @@ -232,15 +232,15 @@ pygments==2.13.0
# sphinx
pyparsing==3.0.9
# via packaging
pyright==1.1.278
pyright==1.1.279
# via -r requirements/tools.in
pytest==7.2.0
# via -r requirements/tools.in
python-dateutil==2.8.2
# via -r requirements/tools.in
pytz==2022.6
# via babel
pyupgrade==3.2.0
pyupgrade==3.2.2
# via shed
pyyaml==6.0
# via
Expand Down Expand Up @@ -312,9 +312,9 @@ sphinxcontrib-serializinghtml==1.1.5
# via sphinx
sqlparse==0.4.3
# via django
stack-data==0.6.0
stack-data==0.6.1
# via ipython
stevedore==4.1.0
stevedore==4.1.1
# via bandit
tokenize-rt==5.0.0
# via pyupgrade
Expand All @@ -341,7 +341,7 @@ types-pkg-resources==0.1.3
# via -r requirements/tools.in
types-pytz==2022.6.0.1
# via -r requirements/tools.in
types-redis==4.3.21.3
types-redis==4.3.21.4
# via -r requirements/tools.in
typing-extensions==4.4.0
# via
Expand All @@ -359,13 +359,13 @@ urllib3==1.26.12
# via
# requests
# twine
virtualenv==20.16.6
virtualenv==20.16.7
# via tox
wcwidth==0.2.5
# via prompt-toolkit
webencodings==0.5.1
# via bleach
wheel==0.38.2
wheel==0.38.4
# via pip-tools
zipp==3.10.0
# via importlib-metadata
Expand Down
2 changes: 2 additions & 0 deletions whole-repo-tests/test_mypy.py
Expand Up @@ -84,6 +84,8 @@ def convert_lines():
# Intentional print so we can check mypy's output if a test fails
print(error_line)
error_code = error_line.split("[")[-1].rstrip("]")
if error_code == "empty-body":
continue
yield (int(col), error_code)

assert sorted(convert_lines()) == sorted(expected)
Expand Down

0 comments on commit 1b2239b

Please sign in to comment.