Skip to content

Commit

Permalink
Get mypy to run without errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Sep 14, 2017
1 parent 8871e48 commit 83178d4
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 28 deletions.
24 changes: 18 additions & 6 deletions src/hypothesis/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
from hypothesis.utils.conventions import UniqueIdentifier, not_set
from hypothesis.utils.dynamicvariables import DynamicVariable

if False:
from typing import Dict, List # noqa

__all__ = [
'settings',
]
Expand All @@ -44,10 +47,10 @@
unlimited = UniqueIdentifier('unlimited')


all_settings = {}
all_settings = {} # type: Dict[str, tuple]


_db_cache = {}
_db_cache = {} # type: dict


class settingsProperty(object):
Expand Down Expand Up @@ -107,7 +110,7 @@ def _assign_default_internal(self, value):
default_variable.value = value


class settings(settingsMeta('settings', (object,), {})):
class settings(settingsMeta('settings', (object,), {})): # type: ignore

"""A settings object controls a variety of parameters that are used in
falsification. These may control both the falsification strategy and the
Expand All @@ -122,7 +125,7 @@ class settings(settingsMeta('settings', (object,), {})):
'_database', '_construction_complete', 'storage'
]
__definitions_are_locked = False
_profiles = {}
_profiles = {} # type: dict

def __getattr__(self, name):
if name in all_settings:
Expand Down Expand Up @@ -488,6 +491,10 @@ class Phase(IntEnum):
shrink = 3


# mypy bug; fixed in HEAD https://github.com/python/mypy/issues/2824
Phase_as_tuple = tuple(Phase) # type: ignore


@unique
class HealthCheck(Enum):
exception_in_generation = 0
Expand All @@ -507,6 +514,11 @@ class Statistics(IntEnum):


class Verbosity(object):
quiet = None # type: Verbosity
normal = None # type: Verbosity
verbose = None # type: Verbosity
debug = None # type: Verbosity
all = None # type: List[Verbosity]

def __repr__(self):
return 'Verbosity.%s' % (self.name,)
Expand Down Expand Up @@ -572,7 +584,7 @@ def by_name(cls, key):

def _validate_phases(phases):
if phases is None:
return tuple(Phase)
return Phase_as_tuple
phases = tuple(phases)
for a in phases:
if not isinstance(a, Phase):
Expand All @@ -582,7 +594,7 @@ def _validate_phases(phases):

settings.define_setting(
'phases',
default=tuple(Phase),
default=Phase_as_tuple,
description=(
'Control which phases should be run. ' +
'See :ref:`the full documentation for more details <phases>`'
Expand Down
4 changes: 3 additions & 1 deletion src/hypothesis/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def __call__(self, *args, **kwargs):
return super(EDMeta, self).__call__(*args, **kwargs)


class ExampleDatabase(EDMeta('ExampleDatabase', (object,), {})):
class ExampleDatabase(
EDMeta('ExampleDatabase', (object,), {}) # type: ignore
):
"""Interface class for storage systems.
A key -> multiple distinct values mapping.
Expand Down
7 changes: 5 additions & 2 deletions src/hypothesis/internal/branchcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

from hypothesis.internal.reflection import proxies

if False:
from typing import Set, Dict, Tuple # noqa

"""
This module implements a custom coverage system that records conditions and
then validates that every condition has been seen to be both True and False
Expand All @@ -36,7 +39,7 @@
itself and has essentially no overhead.
"""

pretty_file_name_cache = {}
pretty_file_name_cache = {} # type: Dict[str, str]


def pretty_file_name(f):
Expand All @@ -54,7 +57,7 @@ def pretty_file_name(f):

if os.getenv('HYPOTHESIS_INTERNAL_BRANCH_CHECK') == 'true':
log = open('branch-check', 'w')
written = set()
written = set() # type: Set[Tuple[str, bool]]

def record_branch(name, value):
key = (name, value)
Expand Down
7 changes: 6 additions & 1 deletion src/hypothesis/internal/charmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
from hypothesis.configuration import tmpdir, storage_directory
from hypothesis.internal.compat import hunichr

if False:
from typing import Dict, Tuple
intervals = Tuple[Tuple[int, int], ...]
cache_type = Dict[Tuple[Tuple[str, ...], int, int, intervals], intervals]


def charmap_file():
return os.path.join(
Expand Down Expand Up @@ -207,7 +212,7 @@ def _query_for_key(key):
return result


limited_category_index_cache = {}
limited_category_index_cache = {} # type: cache_type


def query(
Expand Down
8 changes: 4 additions & 4 deletions src/hypothesis/internal/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
try:
from collections import OrderedDict, Counter
except ImportError: # pragma: no cover
from ordereddict import OrderedDict
from counter import Counter
from ordereddict import OrderedDict # type: ignore
from counter import Counter # type: ignore


PY2 = sys.version_info[0] == 2
Expand Down Expand Up @@ -482,7 +482,7 @@ def implements_iterator(it):


if PY3:
FileNotFoundError = FileNotFoundError
FileNotFoundError = FileNotFoundError # type: Exception
else:
FileNotFoundError = IOError

Expand All @@ -492,7 +492,7 @@ def implements_iterator(it):
if PY3:
# Note: This only works on >= 3.3, but we only support >= 3.3 so that's
# fine
FileExistsError = FileExistsError
FileExistsError = FileExistsError # type: Exception

elif WINDOWS:
FileExistsError = WindowsError
Expand Down
4 changes: 2 additions & 2 deletions src/hypothesis/internal/conjecture/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from random import Random, getrandbits
from weakref import WeakKeyDictionary

from hypothesis import settings as Settings
from hypothesis import Phase
from hypothesis import settings as Settings # type: ignore
from hypothesis import Phase # type: ignore
from hypothesis.reporting import debug_report
from hypothesis.internal.compat import EMPTY_BYTES, Counter, ceil, \
hbytes, hrange, text_type, int_to_text, int_to_bytes, \
Expand Down
5 changes: 3 additions & 2 deletions src/hypothesis/internal/conjecture/floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ def exponent_key(e):


ENCODING_TABLE = array('H', sorted(hrange(MAX_EXPONENT + 1), key=exponent_key))
DECODING_TABLE = array('H', [0]) * len(ENCODING_TABLE)
DECODING_TABLE = array('H', [0]) * len(ENCODING_TABLE) # type: ignore
# https://github.com/python/mypy/issues/3956

for i, b in enumerate(ENCODING_TABLE):
for i, b in enumerate(ENCODING_TABLE): # type: ignore
DECODING_TABLE[b] = i

del i, b
Expand Down
5 changes: 4 additions & 1 deletion src/hypothesis/internal/escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

from hypothesis.errors import DeadlineExceeded

if False:
from typing import Dict # noqa

INTERNAL_PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__))
HYPOTHESIS_ROOT = os.path.dirname(INTERNAL_PACKAGE_DIR)

FILE_CACHE = {}
FILE_CACHE = {} # type: Dict[bytes, bool]


def is_hypothesis_file(filepath):
Expand Down
2 changes: 1 addition & 1 deletion src/hypothesis/internal/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def eval_directory():
return storage_directory('eval_source')


eval_cache = {}
eval_cache = {} # type: dict


def source_exec_as_module(source):
Expand Down
5 changes: 4 additions & 1 deletion src/hypothesis/searchstrategy/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
convert_keyword_arguments, convert_positional_arguments
from hypothesis.searchstrategy.strategies import SearchStrategy

if False:
from typing import Dict # noqa


def tupleize(x):
if isinstance(x, (tuple, list)):
Expand All @@ -30,7 +33,7 @@ def tupleize(x):
return x


unwrap_cache = {}
unwrap_cache = {} # type: Dict[SearchStrategy, SearchStrategy]
unwrap_depth = 0


Expand Down
2 changes: 1 addition & 1 deletion src/hypothesis/searchstrategy/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def __repr__(self):
def do_validate(self):
self.mapped_strategy.validate()

def pack(self, x):
def pack(self, x): # type: ignore
"""Take a value produced by the underlying mapped_strategy and turn it
into a value suitable for outputting from this strategy."""
raise NotImplementedError(
Expand Down
4 changes: 2 additions & 2 deletions src/hypothesis/searchstrategy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def from_typing_type(thing):
else:
_global_type_lookup.update({
typing.ByteString: st.binary(),
typing.io.BinaryIO: st.builds(io.BytesIO, st.binary()),
typing.io.TextIO: st.builds(io.StringIO, st.text()),
typing.io.BinaryIO: st.builds(io.BytesIO, st.binary()), # type: ignore
typing.io.TextIO: st.builds(io.StringIO, st.text()), # type: ignore
typing.Reversible: st.lists(st.integers()),
typing.SupportsAbs: st.complex_numbers(),
typing.SupportsComplex: st.complex_numbers(),
Expand Down
12 changes: 8 additions & 4 deletions src/hypothesis/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
from hypothesis.searchstrategy.collections import TupleStrategy, \
FixedKeysDictStrategy

if False:
from typing import Dict, List # noqa


class TestCaseProperty(object): # pragma: no cover

Expand Down Expand Up @@ -137,6 +140,7 @@ class GenericStateMachine(object):
sequence of example choices demonstrating that.
"""
find_breaking_runner = None # type: classmethod

def steps(self):
"""Return a SearchStrategy instance the defines the available next
Expand Down Expand Up @@ -169,7 +173,7 @@ def check_invariants(self):
"""Called after initializing and after executing each step."""
pass

_test_case_cache = {}
_test_case_cache = {} # type: dict

TestCase = TestCaseProperty()

Expand Down Expand Up @@ -432,9 +436,9 @@ class RuleBasedStateMachine(GenericStateMachine):
executed.
"""
_rules_per_class = {}
_invariants_per_class = {}
_base_rules_per_class = {}
_rules_per_class = {} # type: Dict[type, List[classmethod]]
_invariants_per_class = {} # type: Dict[type, List[classmethod]]
_base_rules_per_class = {} # type: Dict[type, List[classmethod]]

def __init__(self):
if not self.rules():
Expand Down

0 comments on commit 83178d4

Please sign in to comment.