Skip to content

Commit

Permalink
Merge pull request #190 from mrbermell/annotations-and-repr
Browse files Browse the repository at this point in the history
Annotations according to PEP 484 in game.py and model.py
  • Loading branch information
mrbermell authored Dec 22, 2021
2 parents e48e13e + 29d5053 commit 338a4b4
Show file tree
Hide file tree
Showing 7 changed files with 637 additions and 366 deletions.
12 changes: 9 additions & 3 deletions botbowl/core/forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"""
from copy import deepcopy, copy
from enum import Enum
from pytest import set_trace


class Reversible:

def __init__(self, ignored_keys=[]):
def __init__(self, ignored_keys=None):
if ignored_keys is None:
ignored_keys = []
super().__setattr__("_trajectory", None)
super().__setattr__("_ignored_keys", set(ignored_keys))

Expand Down Expand Up @@ -89,7 +90,6 @@ def next_step(self):
self.current_step += 1



class Step:
def undo(self):
raise NotImplementedError("Method to be overwritten by subclass")
Expand Down Expand Up @@ -332,6 +332,12 @@ def is_immutable(obj):
immutable_types = {int, float, str, tuple, bool, range, type(None)}


def treat_as_immutable(cls):
"""Used as decorator for classes that should never be tracked by forward model"""
immutable_types.add(cls)
return cls


def add_reversibility(value, trajectory):
if is_immutable(value):
return value
Expand Down
Loading

0 comments on commit 338a4b4

Please sign in to comment.