Skip to content

Commit 6ec9755

Browse files
committed
Start using typeguard
1 parent 1ec292b commit 6ec9755

File tree

12 files changed

+41
-5
lines changed

12 files changed

+41
-5
lines changed

_starter_kit/src/thing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from typeguard import typechecked
2+
3+
4+
@typechecked
15
class Thing:
26
_can_act: bool
37
_has_acted: bool = False
@@ -15,5 +19,6 @@ def has_acted(self) -> bool:
1519
return self._has_acted
1620

1721

22+
@typechecked
1823
class ThingCantActException(Exception):
1924
pass

_starter_kit/tests/test_thing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
from _starter_kit.src.thing import Thing, ThingCantActException
34

45

fox_goose_corn/src/crossing_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typeguard import typechecked
22

33
from fox_goose_corn.src.model.boat import Boat
44
from fox_goose_corn.src.model.cargo_item import (
@@ -10,6 +10,7 @@
1010
)
1111

1212

13+
@typechecked
1314
class CrossingManager:
1415
def __init__(self, boat: Boat, fox: Fox, goose: Goose, corn: Corn):
1516
self._corn = corn

fox_goose_corn/src/model/boat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22

3-
from fox_goose_corn.src.model.cargo_item import AbstractCargoItem, Fox
3+
from fox_goose_corn.src.model.cargo_item import AbstractCargoItem
44
from fox_goose_corn.src.model.river import RiverSide
55

66

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from abc import abstractmethod, ABC
2-
from typing import Type
1+
from abc import ABC
2+
3+
from typeguard import typechecked
34

45
from fox_goose_corn.src.model.river import RiverSide
56

67

8+
@typechecked
79
class AbstractCargoItem(ABC):
810
_current_side: RiverSide = RiverSide.FARM_SIDE
911

10-
def is_at(self, expected_side: RiverSide) -> None:
12+
def is_at(self, expected_side: RiverSide) -> bool:
1113
return self._current_side is expected_side
1214

1315
def unload_cargo_item_at(self, side: RiverSide) -> None:
@@ -17,17 +19,21 @@ def is_on_same_side_as(self, other_cargo_item: "AbstractCargoItem") -> bool:
1719
return self._current_side == other_cargo_item._current_side
1820

1921

22+
@typechecked
2023
class Fox(AbstractCargoItem):
2124
pass
2225

2326

27+
@typechecked
2428
class Goose(AbstractCargoItem):
2529
pass
2630

2731

32+
@typechecked
2833
class Corn(AbstractCargoItem):
2934
pass
3035

3136

37+
@typechecked
3238
class CargoEatingCargoException(Exception):
3339
pass

fox_goose_corn/src/model/river.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from enum import Enum
22

3+
from typeguard import typechecked
34

5+
6+
@typechecked
47
class RiverSide(Enum):
58
FARM_SIDE: str = "farm-side"
69
MARKET_SIDE: str = "market-side"

list_things/src/continuous_subset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from itertools import accumulate
22
from typing import Optional
33

4+
from typeguard import typechecked
45

6+
7+
@typechecked
58
def continuous_subset_adding_up_to(full_set: list[int], target_sum: int) -> Optional[list[int]]:
69
full_set.sort() # Might improve performance on more random lists if the values are in ascending order
710

list_things/src/scattered_subset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from itertools import combinations
22
from typing import Optional
33

4+
from typeguard import typechecked
45

6+
7+
@typechecked
58
def scattered_subset_adding_up_to(
69
full_set: list[int],
710
target_sum: int,

thing_rental/src/model/person.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
from typeguard import typechecked
2+
3+
4+
@typechecked
15
class Person:
26
pass

thing_rental/src/model/rental.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from typeguard import typechecked
2+
13
from thing_rental.src.model.person import Person
24
from thing_rental.src.model.thing import Thing
35

46

7+
@typechecked
58
class Rental:
69
person: Person
710
thing: Thing

0 commit comments

Comments
 (0)