Misc fixes, Allow get/setting seats via array access on Cinema
This MR:
- Adds a
from __future__ import annotations
totypes.py
, which is needed to have Python not throw a runtime error about thearray[int]
type - Changes
_xy_to_index
to raise aIndexError
instead of aKeyError
if one of the coordinates is out of bounds, as this is a more appropriate error (KeyError
is supposed to be for dictionaries / key-value objects) - Changes
SeatStatus
from aEnum
to anIntEnum
to ensure Python complains if we add a value that's not an integer (this is not a problem now) - Adds
__getitem__
and__setitem__
methods to Cinema, which allows "array access" on a Cinema object like so:
>>> from cinematinator.types import Cinema, SeatStatus
>>> c = Cinema(3, 3)
>>> c[1,2]
<SeatStatus.NoSeat: 32>
>>> c[1,2] = SeatStatus.Available
>>> c[1,2]
<SeatStatus.Available: 111>
>>> c.get_seat(1,2)
<SeatStatus.Available: 111>