Skip to content

Misc fixes, Allow get/setting seats via array access on Cinema

Maarten van den Berg requested to merge cinema-index-access into master

This MR:

  • Adds a from __future__ import annotations to types.py, which is needed to have Python not throw a runtime error about the array[int] type
  • Changes _xy_to_index to raise a IndexError instead of a KeyError 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 a Enum to an IntEnum 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>

Merge request reports

Loading