Skip to content

Commit

Permalink
More typing
Browse files Browse the repository at this point in the history
  • Loading branch information
dwagon committed Oct 23, 2023
1 parent 541b1b8 commit 466d7a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions dominion/Counter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Counter - wrapped integer """
from typing import Any


###############################################################################
Expand All @@ -13,16 +14,16 @@ def get(self) -> int:
"""Get the value"""
return self._value

def set(self, value) -> int:
def set(self, value: int) -> int:
"""Set the value - for debugging"""
self._value = value
return self._value

def add(self, mod):
def add(self, mod: int) -> None:
"""Add to the value"""
self._value += mod

def __add__(self, obj):
def __add__(self, obj: Any) -> "Counter":
if isinstance(obj, int):
self._value += obj
elif hasattr(obj, "get"):
Expand All @@ -31,7 +32,7 @@ def __add__(self, obj):
raise NotImplementedError(f"Counter __add__({obj=}) {type(obj)}")
return Counter(self._name, self._value)

def __sub__(self, obj):
def __sub__(self, obj: Any) -> "Counter":
if isinstance(obj, int):
self._value -= obj
elif hasattr(obj, "get"):
Expand All @@ -40,19 +41,19 @@ def __sub__(self, obj):
raise NotImplementedError(f"Counter __sub__({obj=}) {type(obj)}")
return Counter(self._name, self._value)

def __int__(self):
def __int__(self) -> int:
return self._value

def __repr__(self):
def __repr__(self) -> str:
return f"<{self._name}={self._value}>"

def __bool__(self):
def __bool__(self) -> bool:
return self._value != 0

def __lt__(self, obj):
def __lt__(self, obj: Any) -> bool:
if isinstance(obj, int):
return self._value < obj
if hasattr(obj, "get"):
elif hasattr(obj, "get"):
return self._value < obj.get()
raise NotImplementedError(f"Counter __sub__({obj=}) {type(obj)}")

Expand Down
2 changes: 1 addition & 1 deletion dominion/Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ def _cost_string(self, card: Card) -> str:
###########################################################################
def plr_trash_card(
self, num=1, anynum=False, cardsrc=Piles.HAND, **kwargs
) -> Optional[Card]:
) -> Optional[list[Card]]:
"""Ask player to trash num cards"""
if "prompt" not in kwargs:
kwargs["prompt"] = "Trash any cards" if anynum else f"Trash {num} cards"
Expand Down

0 comments on commit 466d7a4

Please sign in to comment.