Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Godsmith committed Sep 13, 2023
1 parent 7d0bce6 commit a8f7dfa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion trainfinity2/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import arcade
from pyglet.math import Vec2

from trainfinity2.events import Event

from .camera import Camera
from .constants import (
GRID_HEIGHT_PIXELS,
Expand Down Expand Up @@ -231,7 +233,7 @@ def _create_train(
return train

def on_mouse_motion(self, x: int, y: int, dx: int, dy: int):
events = []
events: list[Event] = []
world_x, world_y = self.camera.to_world_coordinates(x, y)
if self.is_mouse2_pressed:
self._on_mouse_move_when_mouse_2_pressed(x, y)
Expand Down
2 changes: 1 addition & 1 deletion trainfinity2/graphics/drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self):
self._sprite_list.append(self._fps_sprite)
self._sprite_list.append(self._score_sprite)

def handle_events(self, events: list[Event]):
def handle_events(self, events: Iterable[Event]):
for event in events:
match event:
case CreateEvent(Mine() as mine):
Expand Down
14 changes: 7 additions & 7 deletions trainfinity2/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict
from dataclasses import dataclass, field
from itertools import pairwise
from typing import Iterable
from typing import Iterable, Sequence

from pyglet.math import Vec2

Expand Down Expand Up @@ -231,7 +231,7 @@ def _is_inside(self, x, y):

def click_and_drag(
self, x: int, y: int, start_x: int, start_y: int, mode: Mode
) -> list[Event]:
) -> Sequence[Event]:
if mode == Mode.RAIL:
return [self._show_rails_being_built(Vec2(start_x, start_y), Vec2(x, y))]
elif mode == Mode.STATION:
Expand Down Expand Up @@ -259,7 +259,7 @@ def _show_rails_being_built(self, start: Vec2, stop: Vec2) -> RailsBeingBuiltEve
return RailsBeingBuiltEvent(self.rails_being_built)

def remove_rail(self, position: Vec2) -> list[Event]:
events = []
events: list[Event] = []
for rail in self.rails_at_position(position):
events.append(DestroyEvent(rail))
keys = [key for key, signal in self.signals.items() if signal.rail == rail]
Expand Down Expand Up @@ -292,7 +292,7 @@ def create_rail(self, rails: set[Rail]) -> list[Event]:
return events

def release_mouse_button(self, mode: Mode) -> list[Event]:
events = []
events: list[Event] = []
if all(rail.legal for rail in self.rails_being_built):
if mode == mode.RAIL:
events.extend(self.create_rail(self.rails_being_built))
Expand Down Expand Up @@ -356,7 +356,7 @@ def _create_station(self, station: Station) -> CreateEvent:
self.station_from_position[position] = station
return CreateEvent(station)

def level_up(self, new_level: int) -> list[Event]:
def level_up(self, new_level: int) -> Sequence[Event]:
events = []
self.left -= 1
self.bottom -= 1
Expand Down Expand Up @@ -394,14 +394,14 @@ def distance_to_rail(rail: Rail, x: float, y: float):

def create_signals_at_click_position(
self, world_x: float, world_y: float
) -> list[Event]:
) -> Sequence[Event]:
# Transpose half a box since rail coordinates are in the bottom left
# of each grid cell while they are visible in the middle
x = world_x - 0.5
y = world_y - 0.5
return self.create_signals_at_grid_position(x, y)

def create_signals_at_grid_position(self, x: float, y: float) -> list[Event]:
def create_signals_at_grid_position(self, x: float, y: float) -> Sequence[Event]:
events = []
if rail := self._closest_rail(x, y):
for position in rail.positions:
Expand Down

0 comments on commit a8f7dfa

Please sign in to comment.