Skip to content

Commit

Permalink
Update type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Nov 14, 2022
1 parent 8524e77 commit a031a3a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/stateful.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions whole-repo-tests/test_mypy.py
Original file line number Diff line number Diff line change
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 a031a3a

Please sign in to comment.