Skip to content

Commit

Permalink
finished parser code
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-s-s committed Oct 19, 2020
1 parent 0b487a6 commit 55d5310
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 845 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ omit =
time_trials/*
doctests.py

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
18 changes: 2 additions & 16 deletions dicetables/new_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def make_die(self, call_node: ast.Call):
kwarg_nodes = call_node.keywords
die_class = self._get_die_class(die_class_name)

instance_for_signature = die_class.__new__(die_class)
die_signature = signature(instance_for_signature.__init__)
die_signature = signature(die_class)

die_params = self._get_params(param_nodes, die_signature)
die_kwargs = self._get_kwargs(kwarg_nodes, die_signature)
Expand Down Expand Up @@ -174,9 +173,6 @@ def _get_kwargs(self, kwarg_nodes, die_signature):
out[kwarg_name] = value
return out

def _update_search_tuple(self, search_tuple):
return tuple(map(self._update_search_string, search_tuple))

def _get_kwarg_value(self, die_signature, kwarg_node):
kwarg_name_to_search_for = self._update_search_string(kwarg_node.arg)
value_node = kwarg_node.value
Expand Down Expand Up @@ -204,8 +200,7 @@ def add_class(self, class_: object):
:param class_: the class you are adding
"""
new_instance = class_.__new__(class_)
die_signature = signature(new_instance.__init__)
die_signature = signature(class_)
self._raise_error_for_missing_annotation(die_signature)
self._raise_error_for_missing_type(die_signature)
self._classes.add(class_)
Expand Down Expand Up @@ -249,12 +244,3 @@ def make_int(num_node):
raise ValueError(f"Expected an integer, but got: {value!r}")
return value


def _get_kwargs_from_init(class_):
try:
kwargs = class_.__init__.__code__.co_varnames
return kwargs[1:]
except AttributeError:
raise AttributeError(
"could not find the code for __init__ function at class_.__init__.__code__"
)
8 changes: 4 additions & 4 deletions dicetables/tools/limit_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ def assert_numbers_of_calls_within_limits(
"""
:raises LimitsError:
"""
pass
raise NotImplementedError

@abstractmethod
def assert_die_size_within_limits(self, bound_args: BoundArguments) -> None:
"""
:raises LimitsError:
"""
pass
raise NotImplementedError

@abstractmethod
def assert_explosions_within_limits(self, bound_args: BoundArguments) -> None:
"""
:raises LimitsError:
"""
pass
raise NotImplementedError

@abstractmethod
def assert_dice_pool_within_limits(self, bound_args: BoundArguments) -> None:
"""
:raises LimitsError:
"""
pass
raise NotImplementedError


class NoOpLimitChecker(AbstractLimitChecker):
Expand Down

0 comments on commit 55d5310

Please sign in to comment.