Skip to content

main

Defines the main Gandalf class.

Gandalf

A Gandalf class.

Attributes:

Name Type Description
colour str

The colour of Gandalf's robes. Defaults to 'grey'.

Source code in src\gandalf\main.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Gandalf:
    """A Gandalf class.

    Attributes:
        colour: The colour of Gandalf's robes. Defaults to 'grey'.
    """

    colour: str = "grey"

    def __init__(self, weapon: WEAPONS = "Staff"):
        """Initialises Gandalf.

        Attributes:
            weapon: The weapon that Gandalf wields, defaults to 'Staff'.
            mount: Gandalf's current steed, defaults to None.
        """
        self._weapon = weapon
        self._mount = None

    @classmethod
    def set_colour(cls, colour: COLOURS):
        """Set Gandalf's colour."""
        if colour not in get_args(COLOURS):
            raise ImproperGandalfColourError
        cls.colour = colour

    @property
    def weapon(self):
        """The weapon property."""
        return self._weapon

    @weapon.setter
    def weapon(self, weapon: WEAPONS):
        """Setter for the weapon property."""
        if weapon not in get_args(WEAPONS):
            raise WrongWeaponError
        self._weapon = weapon

    @property
    def mount(self):
        """Gandalf's mount."""
        return self._mount

    @mount.setter
    def mount(self, mount: Mount):
        """Setter for the mount property."""
        self._mount = mount

    def deny(self, verb: str) -> None:
        """Shout a denial of a doing word.

        Args:
            verb: An action word to deny someone of.
        """
        if not self.weapon == "Staff":
            raise NeedStaffToDenyError("Gandalf doesn't have weapon set to 'Staff'.")
        print(f"YOU SHALL NOT {verb.upper()}!!!")

    def travel(self) -> None:
        """Ride mount to destination."""
        if not self.mount:
            raise NoMountSetError("Gandalf needs a mount to travel.")
        self.mount.ride()

mount property writable

Gandalf's mount.

weapon property writable

The weapon property.

__init__(weapon='Staff')

Initialises Gandalf.

Attributes:

Name Type Description
weapon

The weapon that Gandalf wields, defaults to 'Staff'.

mount

Gandalf's current steed, defaults to None.

Source code in src\gandalf\main.py
19
20
21
22
23
24
25
26
27
def __init__(self, weapon: WEAPONS = "Staff"):
    """Initialises Gandalf.

    Attributes:
        weapon: The weapon that Gandalf wields, defaults to 'Staff'.
        mount: Gandalf's current steed, defaults to None.
    """
    self._weapon = weapon
    self._mount = None

deny(verb)

Shout a denial of a doing word.

Parameters:

Name Type Description Default
verb str

An action word to deny someone of.

required
Source code in src\gandalf\main.py
58
59
60
61
62
63
64
65
66
def deny(self, verb: str) -> None:
    """Shout a denial of a doing word.

    Args:
        verb: An action word to deny someone of.
    """
    if not self.weapon == "Staff":
        raise NeedStaffToDenyError("Gandalf doesn't have weapon set to 'Staff'.")
    print(f"YOU SHALL NOT {verb.upper()}!!!")

set_colour(colour) classmethod

Set Gandalf's colour.

Source code in src\gandalf\main.py
29
30
31
32
33
34
@classmethod
def set_colour(cls, colour: COLOURS):
    """Set Gandalf's colour."""
    if colour not in get_args(COLOURS):
        raise ImproperGandalfColourError
    cls.colour = colour

travel()

Ride mount to destination.

Source code in src\gandalf\main.py
68
69
70
71
72
def travel(self) -> None:
    """Ride mount to destination."""
    if not self.mount:
        raise NoMountSetError("Gandalf needs a mount to travel.")
    self.mount.ride()

ImproperGandalfColourError

Bases: Exception

Raise when user tries to set Gandalf to the wrong colour.

Source code in src\gandalf\main.py
83
84
class ImproperGandalfColourError(Exception):
    """Raise when user tries to set Gandalf to the wrong colour."""

NeedStaffToDenyError

Bases: Exception

Raise when Gandalf tries to deny without his staff.

Source code in src\gandalf\main.py
79
80
class NeedStaffToDenyError(Exception):
    """Raise when Gandalf tries to deny without his staff."""

NoMountSetError

Bases: Exception

Raise when no mount is set for Gandalf..

Source code in src\gandalf\main.py
75
76
class NoMountSetError(Exception):
    """Raise when no mount is set for Gandalf.."""

WrongWeaponError

Bases: Exception

Raise when user tries to set a wrong weapon for Gandalf.

Source code in src\gandalf\main.py
87
88
89
90
91
class WrongWeaponError(Exception):
    """Raise when user tries to set a wrong weapon for Gandalf."""

    def __str__(self):
        return f"Chosen weapon must be one of {get_args(WEAPONS)}"