From f9de04dd336be14ea28bb3f2eb88d7785e21159f Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 22 Apr 2023 20:29:28 -0700 Subject: [PATCH 01/64] 1st version --- arcade/application.py | 130 +++++++++++++++++++------------------- arcade/draw_commands.py | 67 +++++++++++--------- arcade/gl/vertex_array.py | 30 ++++----- arcade/shape_list.py | 34 +++++----- arcade/sprite/sprite.py | 20 +++--- 5 files changed, 143 insertions(+), 138 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 43f5eae18..0f4525ab5 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -31,7 +31,7 @@ _window: 'Window' -def get_screens(): +def get_screens() -> []: """ Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which @@ -97,7 +97,7 @@ def __init__( enable_polling: bool = True, gl_api: str = "gl", draw_rate: float = 1 / 60, - ): + ) -> None: # In certain environments we can't have antialiasing/MSAA enabled. # Detect replit environment if os.environ.get("REPL_ID"): @@ -243,7 +243,7 @@ def clear( color: Optional[RGBA255OrNormalized] = None, normalized: bool = False, viewport: Optional[Tuple[int, int, int, int]] = None, - ): + ) -> None: """Clears the window with the configured background color set through :py:attr:`arcade.Window.background_color`. @@ -289,7 +289,7 @@ def background_color(self) -> Color: return self._background_color @background_color.setter - def background_color(self, value: RGBA255): + def background_color(self, value: RGBA255) -> None: self._background_color = Color.from_iterable(value) def run(self) -> None: @@ -301,7 +301,7 @@ def run(self) -> None: """ arcade.run() - def close(self): + def close(self) -> None: """ Close the Window. """ super().close() # Make sure we don't reference the window any more @@ -313,7 +313,7 @@ def set_fullscreen(self, screen: Optional['Window'] = None, mode: Optional[ScreenMode] = None, width: Optional[float] = None, - height: Optional[float] = None): + height: Optional[float] = None) -> None: """ Set if we are full screen or not. @@ -340,7 +340,7 @@ def center_window(self) -> None: # Center the window self.set_location((screen_width - window_width) // 2, (screen_height - window_height) // 2) - def on_update(self, delta_time: float): + def on_update(self, delta_time: float) -> None: """ Move everything. Perform collision checks. Do all the game logic here. @@ -349,14 +349,14 @@ def on_update(self, delta_time: float): """ pass - def _dispatch_updates(self, delta_time: float): + def _dispatch_updates(self, delta_time: float) -> None: """ Internal function that is scheduled with Pyglet's clock, this function gets run by the clock, and dispatches the on_update events. """ self.dispatch_event('on_update', delta_time) - def set_update_rate(self, rate: float): + def set_update_rate(self, rate: float) -> None: """ Set how often the on_update function should be dispatched. For example, self.set_update_rate(1 / 60) will set the update rate to 60 times per second. @@ -367,7 +367,7 @@ def set_update_rate(self, rate: float): pyglet.clock.unschedule(self._dispatch_updates) pyglet.clock.schedule_interval(self._dispatch_updates, rate) - def set_draw_rate(self, rate: float): + def set_draw_rate(self, rate: float) -> None: """ Set how often the on_draw function should be run. For example, set.set_draw_rate(1 / 60) will set the draw rate to 60 frames per second. @@ -376,7 +376,7 @@ def set_draw_rate(self, rate: float): pyglet.clock.unschedule(pyglet.app.event_loop._redraw_windows) pyglet.clock.schedule_interval(pyglet.app.event_loop._redraw_windows, self._draw_rate) - def on_mouse_motion(self, x: int, y: int, dx: int, dy: int): + def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> None: """ Called repeatedly while the mouse is moving over the window. @@ -389,7 +389,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int): """ pass - def on_mouse_press(self, x: int, y: int, button: int, modifiers: int): + def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> None: """ Called once whenever a mouse button gets pressed down. @@ -413,7 +413,7 @@ def on_mouse_press(self, x: int, y: int, button: int, modifiers: int): """ pass - def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int): + def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int) -> None: """ Called repeatedly while the mouse moves with a button down. @@ -429,7 +429,7 @@ def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifier """ self.on_mouse_motion(x, y, dx, dy) - def on_mouse_release(self, x: int, y: int, button: int, modifiers: int): + def on_mouse_release(self, x: int, y: int, button: int, modifiers: int) -> None: """ Called once whenever a mouse button gets released. @@ -447,7 +447,7 @@ def on_mouse_release(self, x: int, y: int, button: int, modifiers: int): """ pass - def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int): + def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> None: """ Called repeatedly while a mouse scroll wheel moves. @@ -478,7 +478,7 @@ def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int): """ pass - def set_mouse_visible(self, visible: bool = True): + def set_mouse_visible(self, visible: bool = True) -> None: """ Set whether to show the system's cursor while over the window @@ -510,7 +510,7 @@ def set_mouse_visible(self, visible: bool = True): """ super().set_mouse_visible(visible) - def on_key_press(self, symbol: int, modifiers: int): + def on_key_press(self, symbol: int, modifiers: int) -> None: """ Called once when a key gets pushed down. @@ -530,7 +530,7 @@ def on_key_press(self, symbol: int, modifiers: int): except AttributeError: pass - def on_key_release(self, symbol: int, modifiers: int): + def on_key_release(self, symbol: int, modifiers: int) -> None: """ Called once when a key gets released. @@ -554,13 +554,13 @@ def on_key_release(self, symbol: int, modifiers: int): except AttributeError: pass - def on_draw(self): + def on_draw(self) -> None: """ Override this function to add your custom drawing code. """ pass - def on_resize(self, width: int, height: int): + def on_resize(self, width: int, height: int) -> None: """ Override this function to add custom code to be called any time the window is resized. The main responsibility of this method is updating @@ -589,7 +589,7 @@ def on_resize(self, width: int, height: int): original_viewport[2] + height ) - def set_min_size(self, width: int, height: int): + def set_min_size(self, width: int, height: int) -> None: """ Wrap the Pyglet window call to set minimum size :param float width: width in pixels. @@ -601,7 +601,7 @@ def set_min_size(self, width: int, height: int): else: raise ValueError('Cannot set min size on non-resizable window') - def set_max_size(self, width: int, height: int): + def set_max_size(self, width: int, height: int) -> None: """ Wrap the Pyglet window call to set maximum size :param int width: width in pixels. @@ -615,7 +615,7 @@ def set_max_size(self, width: int, height: int): else: raise ValueError('Cannot set max size on non-resizable window') - def set_size(self, width: int, height: int): + def set_size(self, width: int, height: int) -> None: """ Ignore the resizable flag and set the size @@ -643,7 +643,7 @@ def get_location(self) -> Tuple[int, int]: return super().get_location() - def set_visible(self, visible: bool = True): + def set_visible(self, visible: bool = True) -> None: """ Set if the window is visible or not. Normally, a program's window is visible. @@ -652,7 +652,7 @@ def set_visible(self, visible: bool = True): super().set_visible(visible) # noinspection PyMethodMayBeStatic - def set_viewport(self, left: float, right: float, bottom: float, top: float): + def set_viewport(self, left: float, right: float, bottom: float, top: float) -> None: """ Set the viewport. (What coordinates we can see. Used to scale and/or scroll the screen). @@ -671,11 +671,11 @@ def get_viewport(self) -> Tuple[float, float, float, float]: """ Get the viewport. (What coordinates we can see.) """ return self.ctx.projection_2d - def use(self): + def use(self) -> None: """Bind the window's framebuffer for rendering commands""" self.ctx.screen.use() - def test(self, frames: int = 10): + def test(self, frames: int = 10) -> None: """ Used by unit test cases. Runs the event loop a few times and stops. @@ -695,7 +695,7 @@ def test(self, frames: int = 10): time.sleep(sleep_time) self._dispatch_updates(1 / 60) - def show_view(self, new_view: 'View'): + def show_view(self, new_view: 'View') -> None: """ Select the view to show in the next frame. This is not a blocking call showing the view. @@ -761,7 +761,7 @@ def show_view(self, new_view: 'View'): # will still call the Window's event handlers. (See pyglet's EventDispatcher.dispatch_event() implementation # for details) - def hide_view(self): + def hide_view(self) -> None: """ Hide the currently active view (if any) returning us back to ``on_draw`` and ``on_update`` functions in the window. @@ -779,13 +779,13 @@ def hide_view(self): self.remove_handlers(self._current_view) self._current_view = None - def _create(self): + def _create(self) -> None: super()._create() - def _recreate(self, changes): + def _recreate(self, changes) -> None: super()._recreate(changes) - def flip(self): + def flip(self) -> None: """ Window framebuffers normally have a back and front buffer. This method makes the back buffer visible and hides the front buffer. @@ -808,43 +808,43 @@ def flip(self): super().flip() - def switch_to(self): + def switch_to(self) -> None: """ Switch the this window. """ super().switch_to() - def set_caption(self, caption): + def set_caption(self, caption) -> None: """ Set the caption for the window. """ super().set_caption(caption) - def set_minimum_size(self, width: int, height: int): + def set_minimum_size(self, width: int, height: int) -> None: """ Set smallest window size. """ super().set_minimum_size(width, height) - def set_maximum_size(self, width, height): + def set_maximum_size(self, width: int, height: int) -> None: """ Set largest window size. """ super().set_maximum_size(width, height) - def set_location(self, x, y): + def set_location(self, x: int, y: int) -> None: """ Set location of the window. """ super().set_location(x, y) - def activate(self): + def activate(self) -> None: """ Activate this window. """ super().activate() - def minimize(self): + def minimize(self) -> None: """ Minimize the window. """ super().minimize() - def maximize(self): + def maximize(self) -> None: """ Maximize the window. """ super().maximize() - def set_vsync(self, vsync: bool): + def set_vsync(self, vsync: bool) -> None: """ Set if we sync our draws to the monitors vertical sync rate. """ super().set_vsync(vsync) - def set_mouse_platform_visible(self, platform_visible=None): + def set_mouse_platform_visible(self, platform_visible=None) -> None: """ .. warning:: You are probably looking for :meth:`~.Window.set_mouse_visible`! @@ -859,23 +859,23 @@ def set_mouse_platform_visible(self, platform_visible=None): """ super().set_mouse_platform_visible(platform_visible) - def set_exclusive_mouse(self, exclusive=True): + def set_exclusive_mouse(self, exclusive=True) -> None: """ Capture the mouse. """ super().set_exclusive_mouse(exclusive) - def set_exclusive_keyboard(self, exclusive=True): + def set_exclusive_keyboard(self, exclusive=True) -> None: """ Capture all keyboard input. """ super().set_exclusive_keyboard(exclusive) - def get_system_mouse_cursor(self, name): + def get_system_mouse_cursor(self, name) -> None: """ Get the system mouse cursor """ return super().get_system_mouse_cursor(name) - def dispatch_events(self): + def dispatch_events(self) -> None: """ Dispatch events """ super().dispatch_events() - def on_mouse_enter(self, x: int, y: int): + def on_mouse_enter(self, x: int, y: int) -> None: """ Called once whenever the mouse enters the window area on screen. @@ -887,7 +887,7 @@ def on_mouse_enter(self, x: int, y: int): """ pass - def on_mouse_leave(self, x: int, y: int): + def on_mouse_leave(self, x: int, y: int) -> None: """ Called once whenever the mouse leaves the window area on screen. @@ -936,7 +936,7 @@ class View: """ def __init__(self, - window: Optional[Window] = None): + window: Optional[Window] = None) -> None: self.window = arcade.get_window() if window is None else window self.key: Optional[int] = None @@ -972,7 +972,7 @@ def clear( color: Optional[RGBA255OrNormalized] = None, normalized: bool = False, viewport: Optional[Tuple[int, int, int, int]] = None, - ): + ) -> None: """Clears the View's Window with the configured background color set through :py:attr:`arcade.Window.background_color`. @@ -988,19 +988,19 @@ def clear( """ self.window.clear(color, normalized, viewport) - def on_update(self, delta_time: float): + def on_update(self, delta_time: float) -> None: """To be overridden""" pass - def on_draw(self): + def on_draw(self) -> None: """Called when this view should draw""" pass - def on_show(self): + def on_show(self) -> None: """Deprecated. Use :py:meth:`~arcade.View.on_show_view` instead.""" pass - def on_show_view(self): + def on_show_view(self) -> None: """ Called once when the view is shown. @@ -1008,11 +1008,11 @@ def on_show_view(self): """ pass - def on_hide_view(self): + def on_hide_view(self) -> None: """Called once when this view is hidden.""" pass - def on_mouse_motion(self, x: int, y: int, dx: int, dy: int): + def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> None: """ Override this function to add mouse functionality. @@ -1023,7 +1023,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int): """ pass - def on_mouse_press(self, x: int, y: int, button: int, modifiers: int): + def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> None: """ Override this function to add mouse button functionality. @@ -1037,7 +1037,7 @@ def on_mouse_press(self, x: int, y: int, button: int, modifiers: int): """ pass - def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, _buttons: int, _modifiers: int): + def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, _buttons: int, _modifiers: int) -> None: """ Override this function to add mouse button functionality. @@ -1051,7 +1051,7 @@ def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, _buttons: int, _modifi """ self.on_mouse_motion(x, y, dx, dy) - def on_mouse_release(self, x: int, y: int, button: int, modifiers: int): + def on_mouse_release(self, x: int, y: int, button: int, modifiers: int) -> None: """ Override this function to add mouse button functionality. @@ -1065,7 +1065,7 @@ def on_mouse_release(self, x: int, y: int, button: int, modifiers: int): """ pass - def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int): + def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> None: """ User moves the scroll wheel. @@ -1076,7 +1076,7 @@ def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int): """ pass - def on_key_press(self, symbol: int, modifiers: int): + def on_key_press(self, symbol: int, modifiers: int) -> None: """ Override this function to add key press functionality. @@ -1089,7 +1089,7 @@ def on_key_press(self, symbol: int, modifiers: int): except AttributeError: pass - def on_key_release(self, _symbol: int, _modifiers: int): + def on_key_release(self, _symbol: int, _modifiers: int) -> None: """ Override this function to add key release functionality. @@ -1102,7 +1102,7 @@ def on_key_release(self, _symbol: int, _modifiers: int): except AttributeError: pass - def on_resize(self, width: int, height: int): + def on_resize(self, width: int, height: int) -> None: """ Called when the window is resized while this view is active. :py:meth:`~arcade.Window.on_resize` is also called separately. @@ -1111,7 +1111,7 @@ def on_resize(self, width: int, height: int): """ pass - def on_mouse_enter(self, x: int, y: int): + def on_mouse_enter(self, x: int, y: int) -> None: """ Called when the mouse was moved into the window. This event will not be triggered if the mouse is currently being @@ -1122,7 +1122,7 @@ def on_mouse_enter(self, x: int, y: int): """ pass - def on_mouse_leave(self, x: int, y: int): + def on_mouse_leave(self, x: int, y: int) -> None: """ Called when the mouse was moved outside of the window. This event will not be triggered if the mouse is currently being diff --git a/arcade/draw_commands.py b/arcade/draw_commands.py index ea9c41da6..dd6e4f7d6 100644 --- a/arcade/draw_commands.py +++ b/arcade/draw_commands.py @@ -34,7 +34,7 @@ def draw_arc_filled(center_x: float, center_y: float, color: RGBA255, start_angle: float, end_angle: float, tilt_angle: float = 0, - num_segments: int = 128): + num_segments: int = 128) -> None: """ Draw a filled in arc. Useful for drawing pie-wedges, or Pac-Man. @@ -76,7 +76,7 @@ def draw_arc_outline(center_x: float, center_y: float, width: float, height: float, color: RGBA255, start_angle: float, end_angle: float, border_width: float = 1, tilt_angle: float = 0, - num_segments: int = 128): + num_segments: int = 128) -> None: """ Draw the outside edge of an arc. Useful for drawing curved lines. @@ -132,7 +132,7 @@ def draw_arc_outline(center_x: float, center_y: float, width: float, def draw_parabola_filled(start_x: float, start_y: float, end_x: float, height: float, color: RGBA255, - tilt_angle: float = 0): + tilt_angle: float = 0) -> None: """ Draws a filled in parabola. @@ -155,7 +155,7 @@ def draw_parabola_filled(start_x: float, start_y: float, end_x: float, def draw_parabola_outline(start_x: float, start_y: float, end_x: float, height: float, color: RGBA255, - border_width: float = 1, tilt_angle: float = 0): + border_width: float = 1, tilt_angle: float = 0) -> None: """ Draws the outline of a parabola. @@ -185,7 +185,7 @@ def draw_parabola_outline(start_x: float, start_y: float, end_x: float, def draw_circle_filled(center_x: float, center_y: float, radius: float, color: RGBA255, tilt_angle: float = 0, - num_segments: int = -1): + num_segments: int = -1) -> None: """ Draw a filled-in circle. @@ -208,7 +208,7 @@ def draw_circle_filled(center_x: float, center_y: float, radius: float, def draw_circle_outline(center_x: float, center_y: float, radius: float, color: RGBA255, border_width: float = 1, tilt_angle: float = 0, - num_segments: int = -1): + num_segments: int = -1) -> None: """ Draw the outline of a circle. @@ -239,7 +239,7 @@ def draw_circle_outline(center_x: float, center_y: float, radius: float, def draw_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: RGBA255, - tilt_angle: float = 0, num_segments: int = -1): + tilt_angle: float = 0, num_segments: int = -1) -> None: """ Draw a filled in ellipse. @@ -286,7 +286,7 @@ def draw_ellipse_outline(center_x: float, center_y: float, height: float, color: RGBA255, border_width: float = 1, tilt_angle: float = 0, - num_segments: int = -1): + num_segments: int = -1) -> None: """ Draw the outline of an ellipse. @@ -335,7 +335,7 @@ def draw_ellipse_outline(center_x: float, center_y: float, def _generic_draw_line_strip(point_list: PointList, color: RGBA255, - mode: int = gl.GL_LINE_STRIP): + mode: int = gl.GL_LINE_STRIP) -> None: """ Draw a line strip. A line strip is a set of continuously connected line segments. @@ -372,7 +372,8 @@ def _generic_draw_line_strip(point_list: PointList, def draw_line_strip(point_list: PointList, - color: RGBA255, line_width: float = 1): + color: RGBA255, + line_width: float = 1) -> None: """ Draw a multi-point line. @@ -397,7 +398,7 @@ def draw_line_strip(point_list: PointList, def draw_line(start_x: float, start_y: float, end_x: float, end_y: float, - color: RGBA255, line_width: float = 1): + color: RGBA255, line_width: float = 1) -> None: """ Draw a line. @@ -432,7 +433,7 @@ def draw_line(start_x: float, start_y: float, end_x: float, end_y: float, def draw_lines(point_list: PointList, color: RGBA255, - line_width: float = 1): + line_width: float = 1) -> None: """ Draw a set of lines. @@ -472,7 +473,7 @@ def draw_lines(point_list: PointList, # --- BEGIN POINT FUNCTIONS # # # -def draw_point(x: float, y: float, color: RGBA255, size: float): +def draw_point(x: float, y: float, color: RGBA255, size: float) -> None: """ Draw a point. @@ -485,7 +486,7 @@ def draw_point(x: float, y: float, color: RGBA255, size: float): draw_rectangle_filled(x, y, size, size, color) -def draw_points(point_list: PointList, color: RGBA255, size: float = 1): +def draw_points(point_list: PointList, color: RGBA255, size: float = 1) -> None: """ Draw a set of points. @@ -526,7 +527,7 @@ def draw_points(point_list: PointList, color: RGBA255, size: float = 1): def draw_polygon_filled(point_list: PointList, - color: RGBA255): + color: RGBA255) -> None: """ Draw a polygon that is filled in. @@ -540,7 +541,8 @@ def draw_polygon_filled(point_list: PointList, def draw_polygon_outline(point_list: PointList, - color: RGBA255, line_width: float = 1): + color: RGBA255, + line_width: float = 1) -> None: """ Draw a polygon outline. Also known as a "line loop." @@ -571,7 +573,8 @@ def draw_polygon_outline(point_list: PointList, def draw_triangle_filled(x1: float, y1: float, x2: float, y2: float, - x3: float, y3: float, color: RGBA255): + x3: float, y3: float, + color: RGBA255) -> None: """ Draw a filled in triangle. @@ -596,7 +599,7 @@ def draw_triangle_outline(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: RGBA255, - border_width: float = 1): + border_width: float = 1) -> None: """ Draw a the outline of a triangle. @@ -630,7 +633,7 @@ def draw_triangle_outline(x1: float, y1: float, ) def draw_lrtb_rectangle_outline(left: float, right: float, top: float, bottom: float, color: RGBA255, - border_width: float = 1): + border_width: float = 1) -> None: """ Draw a rectangle by specifying left, right, top and bottom edges. @@ -664,7 +667,7 @@ def draw_lrtb_rectangle_outline(left: float, right: float, top: float, def draw_lrbt_rectangle_outline(left: float, right: float, bottom: float, top: float, color: RGBA255, - border_width: float = 1): + border_width: float = 1) -> None: """ Draw a rectangle by specifying left, right, bottom and top edges. @@ -696,7 +699,7 @@ def draw_lrbt_rectangle_outline(left: float, right: float, bottom: float, top: f def draw_xywh_rectangle_outline(bottom_left_x: float, bottom_left_y: float, width: float, height: float, color: RGBA255, - border_width: float = 1): + border_width: float = 1) -> None: """ Draw a rectangle extending from bottom left to top right @@ -716,7 +719,7 @@ def draw_xywh_rectangle_outline(bottom_left_x: float, bottom_left_y: float, def draw_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: RGBA255, - border_width: float = 1, tilt_angle: float = 0): + border_width: float = 1, tilt_angle: float = 0) -> None: """ Draw a rectangle outline. @@ -756,7 +759,7 @@ def draw_rectangle_outline(center_x: float, center_y: float, width: float, new_name="draw_lrbt_rectangle_filled" ) def draw_lrtb_rectangle_filled(left: float, right: float, top: float, - bottom: float, color: RGBA255): + bottom: float, color: RGBA255) -> None: """ Draw a rectangle by specifying left, right, top and bottom edges. @@ -784,7 +787,7 @@ def draw_lrtb_rectangle_filled(left: float, right: float, top: float, draw_rectangle_filled(center_x, center_y, width, height, color) -def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: float, color: RGBA255): +def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: float, color: RGBA255) -> None: """ Draw a rectangle by specifying left, right, bottom and top edges. @@ -810,7 +813,7 @@ def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: fl def draw_xywh_rectangle_filled(bottom_left_x: float, bottom_left_y: float, width: float, height: float, - color: RGBA255): + color: RGBA255) -> None: """ Draw a filled rectangle extending from bottom left to top right @@ -828,7 +831,7 @@ def draw_xywh_rectangle_filled(bottom_left_x: float, bottom_left_y: float, def draw_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: RGBA255, - tilt_angle: float = 0): + tilt_angle: float = 0) -> None: """ Draw a filled-in rectangle. @@ -865,7 +868,7 @@ def draw_scaled_texture_rectangle(center_x: float, center_y: float, texture: Texture, scale: float = 1.0, angle: float = 0, - alpha: int = 255): + alpha: int = 255) -> None: """ Draw a textured rectangle on-screen. @@ -900,7 +903,7 @@ def draw_texture_rectangle(center_x: float, center_y: float, height: float, texture: Texture, angle: float = 0, - alpha: int = 255): + alpha: int = 255) -> None: """ Draw a textured rectangle on-screen. @@ -915,11 +918,13 @@ def draw_texture_rectangle(center_x: float, center_y: float, texture.draw_sized(center_x, center_y, width, height, angle, alpha) -def draw_lrwh_rectangle_textured(bottom_left_x: float, bottom_left_y: float, +def draw_lrwh_rectangle_textured(bottom_left_x: float, + bottom_left_y: float, width: float, height: float, - texture: Texture, angle: float = 0, - alpha: int = 255): + texture: Texture, + angle: float = 0, + alpha: int = 255) -> None: """ Draw a texture extending from bottom left to top right. diff --git a/arcade/gl/vertex_array.py b/arcade/gl/vertex_array.py index ec1e0ab5b..2eada999b 100644 --- a/arcade/gl/vertex_array.py +++ b/arcade/gl/vertex_array.py @@ -42,7 +42,7 @@ def __init__( content: Sequence[BufferDescription], index_buffer: Optional[Buffer] = None, index_element_size: int = 4, - ): + ) -> None: self._ctx = ctx self._program = program self._content = content @@ -60,10 +60,10 @@ def __init__( self.ctx.stats.incr("vertex_array") - def __repr__(self): + def __repr__(self) -> None: return f"" - def __del__(self): + def __del__(self) -> None: # Intercept garbage collection if we are using Context.gc() if self._ctx.gc_mode == "context_gc" and self.glo.value > 0: self._ctx.objects.append(self) @@ -104,7 +104,7 @@ def num_vertices(self) -> int: """ return self._num_vertices - def delete(self): + def delete(self) -> None: """ Destroy the underlying OpenGL resource. Don't use this unless you know exactly what you are doing. @@ -113,7 +113,7 @@ def delete(self): self.glo.value = 0 @staticmethod - def delete_glo(ctx: "Context", glo: gl.GLuint): + def delete_glo(ctx: "Context", glo: gl.GLuint) -> None: """ Delete this object. This is automatically called when this object is garbage collected. @@ -130,7 +130,7 @@ def delete_glo(ctx: "Context", glo: gl.GLuint): def _build( self, program: Program, content: Sequence[BufferDescription], index_buffer - ): + ) -> None: """Build a vertex array compatible with the program passed in""" gl.glGenVertexArrays(1, byref(self.glo)) gl.glBindVertexArray(self.glo) @@ -240,7 +240,7 @@ def _build( def render( self, mode: gl.GLenum, first: int = 0, vertices: int = 0, instances: int = 1 - ): + ) -> None: """Render the VertexArray to the currently active framebuffer. :param GLuint mode: Primitive type to render. TRIANGLES, LINES etc. @@ -259,7 +259,7 @@ def render( else: gl.glDrawArraysInstanced(mode, first, vertices, instances) - def render_indirect(self, buffer: Buffer, mode: gl.GLuint, count, first, stride): + def render_indirect(self, buffer: Buffer, mode: gl.GLuint, count, first, stride) -> None: """ Render the VertexArray to the framebuffer using indirect rendering. @@ -306,7 +306,7 @@ def transform_interleaved( vertices: int = 0, instances: int = 1, buffer_offset=0, - ): + ) -> None: """Run a transform feedback. :param Buffer buffer: The buffer to write the output @@ -361,7 +361,7 @@ def transform_separate( vertices: int = 0, instances: int = 1, buffer_offset=0, - ): + ) -> None: """ Run a transform feedback writing to separate buffers. @@ -445,7 +445,7 @@ def __init__( index_buffer: Optional[Buffer] = None, mode: Optional[int] = None, index_element_size: int = 4, - ): + ) -> None: self._ctx = ctx self._content = list(content or []) self._index_buffer = index_buffer @@ -509,10 +509,10 @@ def num_vertices(self) -> int: return self._num_vertices @num_vertices.setter - def num_vertices(self, value: int): + def num_vertices(self, value: int) -> None: self._num_vertices = value - def append_buffer_description(self, descr: BufferDescription): + def append_buffer_description(self, descr: BufferDescription) -> None: """ Append a new BufferDescription to the existing Geometry. .. Warning:: a Geometry cannot contain two BufferDescriptions which share an attribute name. @@ -597,7 +597,7 @@ def render_indirect( count: int = -1, first: int = 0, stride: int = 0, - ): + ) -> None: """ Render the VertexArray to the framebuffer using indirect rendering. @@ -729,6 +729,6 @@ def _generate_vao(self, program: Program) -> VertexArray: return vao @staticmethod - def _release(ctx): + def _release(ctx) -> None: """Mainly here to count destroyed instances""" ctx.stats.decr("geometry") diff --git a/arcade/shape_list.py b/arcade/shape_list.py index fd03086a8..b50f3a509 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -53,7 +53,7 @@ def __init__( # vbo: Buffer, mode: int = gl.GL_TRIANGLES, program: Optional[Program] = None, - ): + ) -> None: self.ctx = get_window().ctx self.program = program or self.ctx.line_generic_with_colors_program self.mode = mode @@ -71,7 +71,7 @@ def __init__( self.geometry = None self.buffer = None - def _init_geometry(self): + def _init_geometry(self) -> None: # NOTE: When drawing a single shape we're not using an index buffer self.buffer = self.program.ctx.buffer(data=self.data) self.geometry = self.ctx.geometry( @@ -84,7 +84,7 @@ def _init_geometry(self): ] ) - def draw(self): + def draw(self) -> None: """ Draw this shape. Drawing this way isn't as fast as drawing multiple shapes batched together in a ShapeElementList. @@ -730,7 +730,7 @@ class ShapeElementList(Generic[TShape]): Adding new shapes is fast, but removing them is slow. """ - def __init__(self): + def __init__(self) -> None: # The context this shape list belongs to self.ctx = get_window().ctx # List of sprites in the sprite list @@ -744,7 +744,7 @@ def __init__(self): self.batches: Dict[int, _Batch] = OrderedDict() self.dirties = set() - def append(self, item: TShape): + def append(self, item: TShape) -> None: """ Add a new shape to the list. """ @@ -763,7 +763,7 @@ def append(self, item: TShape): # Mark the group as dirty self.dirties.add(batch) - def remove(self, item: TShape): + def remove(self, item: TShape) -> None: """ Remove a specific shape from the list. """ @@ -814,7 +814,7 @@ def clear(self, position: bool = True, angle: bool = True) -> None: if angle: self.angle = 0 - def move(self, change_x: float, change_y: float): + def move(self, change_x: float, change_y: float) -> None: """ Change the center_x/y of the shape list relative to the current position. @@ -834,7 +834,7 @@ def position(self) -> Tuple[float, float]: return self._center_x, self._center_y @position.setter - def position(self, value: Tuple[float, float]): + def position(self, value: Tuple[float, float]) -> None: self._center_x, self._center_y = value @property @@ -843,7 +843,7 @@ def center_x(self) -> float: return self._center_x @center_x.setter - def center_x(self, value: float): + def center_x(self, value: float) -> None: self._center_x = value @property @@ -852,7 +852,7 @@ def center_y(self) -> float: return self._center_y @center_y.setter - def center_y(self, value: float): + def center_y(self, value: float) -> None: self._center_y = value @property @@ -861,7 +861,7 @@ def angle(self) -> float: return self._angle @angle.setter - def angle(self, value: float): + def angle(self, value: float) -> None: self._angle = value def __len__(self) -> int: @@ -872,7 +872,7 @@ def __iter__(self) -> Iterable[TShape]: """ Return an iterable object of sprites. """ return iter(self.shape_list) - def __getitem__(self, i): + def __getitem__(self, i) -> TShape: return self.shape_list[i] @@ -894,7 +894,7 @@ def __init__( ctx: ArcadeContext, program: Program, mode: int, - ): + ) -> None: self.ctx = ctx self.program = program self.mode = mode @@ -919,22 +919,22 @@ def __init__( self.elements = 0 # Total elements in the batch self.FLAGS = 0 # Flags to indicate changes - def draw(self): + def draw(self) -> None: """Draw the batch.""" if self.elements == 0: return self.geometry.render(self.program, vertices=self.elements, mode=self.mode) - def append(self, item: TShape): + def append(self, item: TShape) -> None: self.new_items.append(item) self.FLAGS |= self.ADD - def remove(self, item: TShape): + def remove(self, item: TShape) -> None: self.items.remove(item) self.FLAGS |= self.REMOVE - def update(self): + def update(self) -> None: """Update the internals of the batch.""" if self.FLAGS == 0: return diff --git a/arcade/sprite/sprite.py b/arcade/sprite/sprite.py index 75ffd19de..08046c611 100644 --- a/arcade/sprite/sprite.py +++ b/arcade/sprite/sprite.py @@ -65,7 +65,7 @@ def __init__( center_y: float = 0.0, angle: float = 0.0, **kwargs, - ): + ) -> None: if isinstance(path_or_texture, Texture): _texture = path_or_texture _textures = [_texture] @@ -129,7 +129,7 @@ def angle(self) -> float: return self._angle @angle.setter - def angle(self, new_value: float): + def angle(self, new_value: float) -> None: if new_value == self._angle: return @@ -151,7 +151,7 @@ def radians(self) -> float: return self._angle / 180.0 * math.pi @radians.setter - def radians(self, new_value: float): + def radians(self, new_value: float) -> None: self.angle = new_value * 180.0 / math.pi @property @@ -172,7 +172,7 @@ def velocity(self) -> Point: return self._velocity @velocity.setter - def velocity(self, new_value: Point): + def velocity(self, new_value: Point) -> None: self._velocity = new_value @property @@ -181,7 +181,7 @@ def change_x(self) -> float: return self.velocity[0] @change_x.setter - def change_x(self, new_value: float): + def change_x(self, new_value: float) -> None: self._velocity = new_value, self._velocity[1] @property @@ -190,7 +190,7 @@ def change_y(self) -> float: return self.velocity[1] @change_y.setter - def change_y(self, new_value: float): + def change_y(self, new_value: float) -> None: self._velocity = self._velocity[0], new_value @property @@ -201,7 +201,7 @@ def hit_box(self) -> HitBox: return self._hit_box @hit_box.setter - def hit_box(self, hit_box: Union[HitBox, RotatableHitBox]): + def hit_box(self, hit_box: Union[HitBox, RotatableHitBox]) -> None: if type(hit_box) == HitBox: self._hit_box = hit_box.create_rotatable(self.angle) else: @@ -215,7 +215,7 @@ def texture(self) -> Texture: return self._texture @texture.setter - def texture(self, texture: Texture): + def texture(self, texture: Texture) -> None: if texture == self._texture: return @@ -253,7 +253,7 @@ def properties(self) -> Dict[str, Any]: return self._properties @properties.setter - def properties(self, value): + def properties(self, value) -> None: self._properties = value # --- Movement methods ----- @@ -370,7 +370,7 @@ def update_spatial_hash(self) -> None: if sprite_list.spatial_hash is not None: sprite_list.spatial_hash.move(self) - def append_texture(self, texture: Texture): + def append_texture(self, texture: Texture) -> None: """ Appends a new texture to the list of textures that can be applied to this sprite. From 4cc412cd901e8141f9d11097473d8e113575e238 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 09:30:08 -0700 Subject: [PATCH 02/64] Add more Type Hints --- arcade/application.py | 18 +++++------ arcade/context.py | 2 +- arcade/easing.py | 53 ++++++++++++++++++------------- arcade/gui/property.py | 72 +++++++++++++++++++++--------------------- arcade/math.py | 16 +++++----- arcade/perf_info.py | 7 ++-- 6 files changed, 88 insertions(+), 80 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 0f4525ab5..803ec1add 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -219,7 +219,7 @@ def __init__( self.mouse = None @property - def current_view(self) -> Optional["View"]: + def current_view(self) -> Optional[View]: """ This property returns the current view being shown. To set a different view, call the @@ -695,7 +695,7 @@ def test(self, frames: int = 10) -> None: time.sleep(sleep_time) self._dispatch_updates(1 / 60) - def show_view(self, new_view: 'View') -> None: + def show_view(self, new_view: View) -> None: """ Select the view to show in the next frame. This is not a blocking call showing the view. @@ -782,7 +782,7 @@ def hide_view(self) -> None: def _create(self) -> None: super()._create() - def _recreate(self, changes) -> None: + def _recreate(self, changes: [str]) -> None: super()._recreate(changes) def flip(self) -> None: @@ -812,7 +812,7 @@ def switch_to(self) -> None: """ Switch the this window. """ super().switch_to() - def set_caption(self, caption) -> None: + def set_caption(self, caption: str) -> None: """ Set the caption for the window. """ super().set_caption(caption) @@ -844,7 +844,7 @@ def set_vsync(self, vsync: bool) -> None: """ Set if we sync our draws to the monitors vertical sync rate. """ super().set_vsync(vsync) - def set_mouse_platform_visible(self, platform_visible=None) -> None: + def set_mouse_platform_visible(self, platform_visible: bool=None) -> None: """ .. warning:: You are probably looking for :meth:`~.Window.set_mouse_visible`! @@ -859,15 +859,15 @@ def set_mouse_platform_visible(self, platform_visible=None) -> None: """ super().set_mouse_platform_visible(platform_visible) - def set_exclusive_mouse(self, exclusive=True) -> None: + def set_exclusive_mouse(self, exclusive: bool=True) -> None: """ Capture the mouse. """ super().set_exclusive_mouse(exclusive) - def set_exclusive_keyboard(self, exclusive=True) -> None: + def set_exclusive_keyboard(self, exclusive: bool=True) -> None: """ Capture all keyboard input. """ super().set_exclusive_keyboard(exclusive) - def get_system_mouse_cursor(self, name) -> None: + def get_system_mouse_cursor(self, name: str) -> Optional["DefualtMouseCursor", "XlibMouseCursor"]: """ Get the system mouse cursor """ return super().get_system_mouse_cursor(name) @@ -957,7 +957,7 @@ def has_sections(self) -> bool: else: return self.section_manager.has_sections - def add_section(self, section, at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: + def add_section(self, section: Optional[SectionManager], at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: """ Adds a section to the view Section Manager. diff --git a/arcade/context.py b/arcade/context.py index 3fed60541..b9646e564 100644 --- a/arcade/context.py +++ b/arcade/context.py @@ -42,7 +42,7 @@ class ArcadeContext(Context): atlas_size = 512, 512 - def __init__(self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "gl"): + def __init__(self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "gl") -> None: super().__init__(window, gc_mode=gc_mode, gl_api=gl_api) diff --git a/arcade/easing.py b/arcade/easing.py index 3577c5c15..bc58e3f9f 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -19,7 +19,7 @@ class EasingData: end_value: float ease_function: Callable - def reset(self): + def reset(self) -> None: self.cur_period = self.start_period @@ -145,7 +145,9 @@ def easing(percent: float, easing_data: EasingData) -> float: easing_data.ease_function(percent) -def ease_angle(start_angle: float, end_angle: float, *, time=None, rate=None, ease_function: Callable = linear): +def ease_angle(start_angle: float, end_angle: float, *, + time=None, rate=None, ease_function: Callable = linear + ) -> EasingData: """ Set up easing for angles. """ @@ -174,16 +176,16 @@ def ease_angle(start_angle: float, end_angle: float, *, time=None, rate=None, ea return easing_data -def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple: +def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, EasingData]: """ Update angle easing. """ - done = False + done: bool = False easing_data.cur_period += delta_time easing_data.cur_period = min(easing_data.cur_period, easing_data.end_period) - percent = easing_data.cur_period / easing_data.end_period + percent: float = easing_data.cur_period / easing_data.end_period - angle = easing(percent, easing_data) + angle: EasingData = easing(percent, easing_data) if percent >= 1.0: done = True @@ -197,17 +199,20 @@ def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple: return done, angle -def ease_value(start_value: float, end_value: float, *, time=None, rate=None, ease_function=linear): +def ease_value(start_value: float, end_value: float, *, time: + Optional[float]=None, rate: Optional[float]=None, + ease_function: Callable=linear) -> EasingData: """ Get an easing value """ - if rate is not None: - diff = abs(start_value - end_value) - time = diff / rate - if time is None: + if not time or not rate: raise ValueError("Either the 'time' or the 'rate' parameter needs to be set.") + if rate: + diff = abs(start_value - end_value) + time: float = diff / rate + easing_data = EasingData(start_value=start_value, end_value=end_value, start_period=0, @@ -217,11 +222,15 @@ def ease_value(start_value: float, end_value: float, *, time=None, rate=None, ea return easing_data -def ease_position(start_position, end_position, *, time=None, rate=None, ease_function=linear): +def ease_position(start_position: Tuple[float, float], + end_position: Tuple[float, float], *, + time: Optional[float]=None, rate: + Optional[float]=None, ease_function: Callable=linear + ) -> Tuple[EasingData, EasingData]: """ Get an easing position """ - distance = get_distance(start_position[0], + distance: float = get_distance(start_position[0], start_position[1], end_position[0], end_position[1]) @@ -229,24 +238,24 @@ def ease_position(start_position, end_position, *, time=None, rate=None, ease_fu if rate is not None: time = distance / rate - easing_data_x = ease_value(start_position[0], end_position[0], time=time, ease_function=ease_function) - easing_data_y = ease_value(start_position[1], end_position[1], time=time, ease_function=ease_function) + easing_data_x: EasingData = ease_value(start_position[0], end_position[0], time=time, ease_function=ease_function) + easing_data_y: EasingData = ease_value(start_position[1], end_position[1], time=time, ease_function=ease_function) return easing_data_x, easing_data_y -def ease_update(easing_data: EasingData, delta_time: float) -> Tuple: +def ease_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, float]: """ Update easing between two values/ """ easing_data.cur_period += delta_time - easing_data.cur_period = min(easing_data.cur_period, easing_data.end_period) + easing_data.cur_period: float = min(easing_data.cur_period, easing_data.end_period) if easing_data.end_period == 0: - percent = 1.0 - value = easing_data.end_value + percent: float = 1.0 + value: EasingData = easing_data.end_value else: - percent = easing_data.cur_period / easing_data.end_period - value = easing(percent, easing_data) + percent: float = easing_data.cur_period / easing_data.end_period + value: EasingData = easing(percent, easing_data) - done = percent >= 1.0 + done: bool = percent >= 1.0 return done, value diff --git a/arcade/gui/property.py b/arcade/gui/property.py index f4003e735..d57be62a7 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -11,7 +11,7 @@ class _Obs: __slots__ = "value", "listeners" - def __init__(self): + def __init__(self) -> None: self.value = None # This will keep any added listener even if it is not referenced anymore and would be garbage collected self.listeners = set() @@ -31,14 +31,14 @@ class Property: __slots__ = "name", "default_factory", "obs" name: str - def __init__(self, default=None, default_factory=None): + def __init__(self, default: Optional[object]=None, default_factory: callable=None) -> None: if default_factory is None: default_factory = lambda prop, instance: default self.default_factory = default_factory self.obs = WeakKeyDictionary() - def _get_obs(self, instance) -> _Obs: + def _get_obs(self, instance: Optional[object]) -> _Obs: obs = self.obs.get(instance) if obs is None: obs = _Obs() @@ -46,17 +46,17 @@ def _get_obs(self, instance) -> _Obs: self.obs[instance] = obs return obs - def get(self, instance): + def get(self, instance: Optional[object]) -> Optional[object]: obs = self._get_obs(instance) return obs.value - def set(self, instance, value): + def set(self, instance: Optional[object], value: Optional[object]) -> None: obs = self._get_obs(instance) if obs.value != value: obs.value = value self.dispatch(instance, value) - def dispatch(self, instance, value): + def dispatch(self, instance: Optional[object], value: Optional[object]) -> None: obs = self._get_obs(instance) for listener in obs.listeners: try: @@ -68,25 +68,25 @@ def dispatch(self, instance, value): ) traceback.print_exc() - def bind(self, instance, callback): + def bind(self, instance: Optional[object], callback: callable) -> None: obs = self._get_obs(instance) # Instance methods are bound methods, which can not be referenced by normal `ref()` # if listeners would be a WeakSet, we would have to add listeners as WeakMethod ourselves into `WeakSet.data`. obs.listeners.add(callback) - def __set_name__(self, owner, name): + def __set_name__(self, owner, name: str): self.name = name - def __get__(self, instance, owner): + def __get__(self, instance: Optional[object], owner) -> Optional[object]: if instance is None: return self return self.get(instance) - def __set__(self, instance, value): + def __set__(self, instance: Optional[object], value: Optional[object]) -> None: self.set(instance, value) -def bind(instance, property: str, callback): +def bind(instance, property: str, callback: callable) -> None: """ Binds a function to the change event of the property. A reference to the function will be kept, so that it will be still invoked, even if it would normally have been garbage collected. @@ -116,23 +116,23 @@ class MyObject: class _ObservableDict(dict): # Internal class to observe changes inside a native python dict. - def __init__(self, prop: Property, instance, *largs): + def __init__(self, prop: Property, instance, *largs) -> None: self.prop: Property = prop self.obj = ref(instance) super().__init__(*largs) - def dispatch(self): + def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: dict.__setitem__(self, key, value) self.dispatch() - def __delitem__(self, key): + def __delitem__(self, key) -> None: dict.__delitem__(self, key) self.dispatch() - def clear(self): + def clear(self) -> None: dict.clear(self) self.dispatch() @@ -146,11 +146,11 @@ def popitem(self): self.dispatch() return result - def setdefault(self, *largs): + def setdefault(self, *largs) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs): + def update(self, *largs) -> None: dict.update(self, *largs) self.dispatch() @@ -161,72 +161,72 @@ class DictProperty(Property): Only dict are allowed. Any other classes are forbidden. """ - def __init__(self): + def __init__(self) -> None: super().__init__(default_factory=_ObservableDict) - def set(self, instance, value: dict): + def set(self, instance, value: dict) -> None: value = _ObservableDict(self, instance, value) super().set(instance, value) class _ObservableList(list): # Internal class to observe changes inside a native python list. - def __init__(self, prop: Property, instance, *largs): + def __init__(self, prop: Property, instance, *largs) -> None: self.prop: Property = prop self.obj = ref(instance) super().__init__(*largs) - def dispatch(self): + def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key, value): + def __setitem__(self, key, value) -> None: list.__setitem__(self, key, value) self.dispatch() - def __delitem__(self, key): + def __delitem__(self, key) -> None: list.__delitem__(self, key) self.dispatch() - def __iadd__(self, *largs): # type: ignore + def __iadd__(self, *largs) -> None: # type: ignore list.__iadd__(self, *largs) self.dispatch() return self - def __imul__(self, *largs): # type: ignore + def __imul__(self, *largs) -> None: # type: ignore list.__imul__(self, *largs) self.dispatch() return self - def append(self, *largs): + def append(self, *largs) -> None: list.append(self, *largs) self.dispatch() - def clear(self): + def clear(self) -> None: list.clear(self) self.dispatch() - def remove(self, *largs): + def remove(self, *largs) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs): + def insert(self, *largs) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs): + def pop(self, *largs) -> None: result = list.pop(self, *largs) self.dispatch() return result - def extend(self, *largs): + def extend(self, *largs) -> None: list.extend(self, *largs) self.dispatch() - def sort(self, **kwargs): + def sort(self, **kwargs) -> None: list.sort(self, **kwargs) self.dispatch() - def reverse(self): + def reverse(self) -> None: list.reverse(self) self.dispatch() @@ -237,9 +237,9 @@ class ListProperty(Property): Only list are allowed. Any other classes are forbidden. """ - def __init__(self): + def __init__(self) -> None: super().__init__(default_factory=_ObservableList) - def set(self, instance, value: dict): + def set(self, instance, value: dict) -> None: value = _ObservableList(self, instance, value) # type: ignore super().set(instance, value) diff --git a/arcade/math.py b/arcade/math.py index ad33f453e..f45e1f32b 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -205,37 +205,37 @@ class _Vec2: """ __slots__ = ['x', 'y'] - def __init__(self, x: float, y: float): + def __init__(self, x: float, y: float) -> None: # see if first argument is an iterable with two items self.x: float = x self.y: float = y @staticmethod - def from_polar(angle, radius): + def from_polar(angle, radius: float) -> _Vec2: rads = math.radians(angle) return _Vec2(radius * math.cos(rads), radius * math.sin(rads)) - def __add__(self, other): + def __add__(self, other: object) -> _Vec2: return _Vec2(self.x + other.x, self.y + other.y) - def __sub__(self, other): + def __sub__(self, other: object) -> _Vec2: return _Vec2(self.x - other.x, self.y - other.y) - def __mul__(self, other): + def __mul__(self, other: object) -> _Vec2: return _Vec2(self.x * other.x, self.y * other.y) - def __truediv__(self, other): + def __truediv__(self, other: object) -> _Vec2: return _Vec2(self.x / other.x, self.y / other.y) def __iter__(self): yield self.x yield self.y - def length(self): + def length(self) -> float: """return the length (magnitude) of the vector""" return math.sqrt(self.x**2 + self.y**2) - def dot(self, other): + def dot(self, other: object) -> float: return self.x * other.x + self.y * other.y def __repr__(self): diff --git a/arcade/perf_info.py b/arcade/perf_info.py index a48c17ce5..33193837e 100644 --- a/arcade/perf_info.py +++ b/arcade/perf_info.py @@ -14,7 +14,7 @@ _max_history: int = 100 -def _dispatch_event(self, *args): +def _dispatch_event(self, *args) -> None: """ This function will be monkey-patched over Pyglet's dispatch event function. """ @@ -49,7 +49,7 @@ def _dispatch_event(self, *args): data.popleft() -def print_timings(): +def print_timings() -> None: """ Print event handler statistics to stdout as a table. @@ -77,8 +77,7 @@ def print_timings(): on_draw 60 0.0020 """ global _timings - print() - print("Event Count Average Time") + print("\nEvent Count Average Time") print("-------------- ----- ------------") for index in _timings: data = _timings[index] From 2c4ecc827ebf7c87b0c1b85fb30af42778aab19d Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 11:25:21 -0700 Subject: [PATCH 03/64] Fix cspotcode's review --- arcade/application.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 803ec1add..d9d4195d7 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -18,7 +18,7 @@ from arcade import set_window from arcade.color import TRANSPARENT_BLACK from arcade.context import ArcadeContext -from arcade.types import Color, RGBA255, RGBA255OrNormalized +from arcade.types import Color, RGBA255, RGBA255OrNormalized, DefaultMouseCursor, XlibMouseCursor from arcade import SectionManager from arcade.utils import is_raspberry_pi @@ -31,7 +31,7 @@ _window: 'Window' -def get_screens() -> []: +def get_screens() -> list: """ Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which @@ -844,7 +844,7 @@ def set_vsync(self, vsync: bool) -> None: """ Set if we sync our draws to the monitors vertical sync rate. """ super().set_vsync(vsync) - def set_mouse_platform_visible(self, platform_visible: bool=None) -> None: + def set_mouse_platform_visible(self, platform_visible: Optional[bool]=None) -> None: """ .. warning:: You are probably looking for :meth:`~.Window.set_mouse_visible`! @@ -867,7 +867,7 @@ def set_exclusive_keyboard(self, exclusive: bool=True) -> None: """ Capture all keyboard input. """ super().set_exclusive_keyboard(exclusive) - def get_system_mouse_cursor(self, name: str) -> Optional["DefualtMouseCursor", "XlibMouseCursor"]: + def get_system_mouse_cursor(self, name: str) -> Optional[DefualtMouseCursor, XlibMouseCursor]: """ Get the system mouse cursor """ return super().get_system_mouse_cursor(name) From 0d166e42980617c2a3b97e66ad4568c244a6bf02 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 11:29:13 -0700 Subject: [PATCH 04/64] Add types to sprite.py --- arcade/sprite/sprite.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arcade/sprite/sprite.py b/arcade/sprite/sprite.py index 08046c611..6d4a12499 100644 --- a/arcade/sprite/sprite.py +++ b/arcade/sprite/sprite.py @@ -1,6 +1,6 @@ import math from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, Callable from arcade import Texture, load_texture from arcade.hitbox import HitBox, RotatableHitBox @@ -8,6 +8,8 @@ from arcade.texture import get_default_texture from arcade.types import PathOrTexture, Point +from __future__ import annotations + from .base import BasicSprite from .mixins import PymunkMixin From 3076ed47c431e162b118a705b3f8a2eaea63eb32 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 11:33:02 -0700 Subject: [PATCH 05/64] Try to fix some issues --- arcade/gl/vertex_array.py | 4 ++-- arcade/gui/property.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arcade/gl/vertex_array.py b/arcade/gl/vertex_array.py index 2eada999b..53aed37da 100644 --- a/arcade/gl/vertex_array.py +++ b/arcade/gl/vertex_array.py @@ -60,7 +60,7 @@ def __init__( self.ctx.stats.incr("vertex_array") - def __repr__(self) -> None: + def __repr__(self) -> str: return f"" def __del__(self) -> None: @@ -69,7 +69,7 @@ def __del__(self) -> None: self._ctx.objects.append(self) @property - def ctx(self) -> "Context": + def ctx(self) -> Context: """ The Context this object belongs to diff --git a/arcade/gui/property.py b/arcade/gui/property.py index d57be62a7..70ff8c1cd 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -187,12 +187,12 @@ def __delitem__(self, key) -> None: list.__delitem__(self, key) self.dispatch() - def __iadd__(self, *largs) -> None: # type: ignore + def __iadd__(self, *largs): # type: ignore list.__iadd__(self, *largs) self.dispatch() return self - def __imul__(self, *largs) -> None: # type: ignore + def __imul__(self, *largs): # type: ignore list.__imul__(self, *largs) self.dispatch() return self From 97cb872150ec32b2aabf3e601228fef6af8f5285 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 12:11:43 -0700 Subject: [PATCH 06/64] Fixed more github stuff --- arcade/application.py | 5 +++-- arcade/sprite_list/sprite_list.py | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index d9d4195d7..3f30a5a33 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -11,6 +11,7 @@ import pyglet.gl as gl from pyglet.canvas.base import ScreenMode +from pyglet.window import MouseCursor, DefaultMouseCursor import arcade from arcade import get_display_size @@ -18,7 +19,7 @@ from arcade import set_window from arcade.color import TRANSPARENT_BLACK from arcade.context import ArcadeContext -from arcade.types import Color, RGBA255, RGBA255OrNormalized, DefaultMouseCursor, XlibMouseCursor +from arcade.types import Color, RGBA255, RGBA255OrNormalized from arcade import SectionManager from arcade.utils import is_raspberry_pi @@ -957,7 +958,7 @@ def has_sections(self) -> bool: else: return self.section_manager.has_sections - def add_section(self, section: Optional[SectionManager], at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: + def add_section(self, section: Optional["Section"], at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: """ Adds a section to the view Section Manager. diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 26f0586d3..aacaac34d 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -902,7 +902,7 @@ def write_sprite_buffers_to_gpu(self) -> None: """ self._write_sprite_buffers_to_gpu() - def _write_sprite_buffers_to_gpu(self): + def _write_sprite_buffers_to_gpu(self) -> None: LOG.debug( "[%s] SpriteList._write_sprite_buffers_to_gpu: pos=%s, size=%s, angle=%s, color=%s tex=%s idx=%s", id(self), @@ -957,7 +957,7 @@ def initialize(self): """ self._init_deferred() - def draw(self, *, filter=None, pixelated=None, blend_function=None): + def draw(self, *, filter: Optional["gl filter"]=None, pixelated: bool=False, blend_function: Optional["gl blend function"]=None) -> None: """ Draw this list of sprites. @@ -1014,7 +1014,7 @@ def draw_hit_boxes(self, color: RGBA255 = (0, 0, 0, 255), line_thickness: float for sprite in self.sprite_list: sprite.draw_hit_box(color, line_thickness) - def _normalize_index_buffer(self): + def _normalize_index_buffer(self) -> None: """ Removes unused slots in the index buffer. The other buffers don't need this because they re-use slots. @@ -1033,7 +1033,7 @@ def _normalize_index_buffer(self): # NOTE: Right now the index buffer is always normalized pass - def _grow_sprite_buffers(self): + def _grow_sprite_buffers(self) -> None: """Double the internal buffer sizes""" # Resize sprite buffers if needed if self._sprite_buffer_slots <= self._buf_capacity: @@ -1070,7 +1070,7 @@ def _grow_sprite_buffers(self): self._sprite_color_changed = True self._sprite_texture_changed = True - def _grow_index_buffer(self): + def _grow_index_buffer(self) -> None: # Extend the index buffer capacity if needed if self._sprite_index_slots <= self._idx_capacity: return @@ -1098,7 +1098,7 @@ def _grow_index_buffer(self): self._sprite_index_changed = True - def _update_all(self, sprite: SpriteType): + def _update_all(self, sprite: SpriteType) -> None: """ Update all sprite data. This is faster when adding and moving sprites. This duplicate code, but reduces call overhead, dict lookups etc. @@ -1137,7 +1137,7 @@ def _update_all(self, sprite: SpriteType): self._sprite_texture_data[slot] = tex_slot self._sprite_texture_changed = True - def _update_texture(self, sprite) -> None: + def _update_texture(self, sprite: SpriteType) -> None: """Make sure we update the texture for this sprite for the next batch drawing""" # We cannot interact with texture atlases unless the context From c3c590f088f1ac36a6289c812bb2f58bae30d0b1 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 12:19:42 -0700 Subject: [PATCH 07/64] Fix easing.py somewhat --- arcade/easing.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arcade/easing.py b/arcade/easing.py index bc58e3f9f..32b669602 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -3,7 +3,8 @@ """ from math import pi, sin, cos from dataclasses import dataclass -from typing import Callable, Tuple +from typing import Callable, Tuple, Optional, Union +from __future__ import annotations from .math import get_distance @@ -147,7 +148,7 @@ def easing(percent: float, easing_data: EasingData) -> float: def ease_angle(start_angle: float, end_angle: float, *, time=None, rate=None, ease_function: Callable = linear - ) -> EasingData: + ) -> Optional[EasingData]: """ Set up easing for angles. """ @@ -185,7 +186,7 @@ def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, easing_data.cur_period = min(easing_data.cur_period, easing_data.end_period) percent: float = easing_data.cur_period / easing_data.end_period - angle: EasingData = easing(percent, easing_data) + angle: float = easing(percent, easing_data) if percent >= 1.0: done = True @@ -211,7 +212,7 @@ def ease_value(start_value: float, end_value: float, *, time: if rate: diff = abs(start_value - end_value) - time: float = diff / rate + time = diff / rate easing_data = EasingData(start_value=start_value, end_value=end_value, @@ -249,13 +250,13 @@ def ease_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, float Update easing between two values/ """ easing_data.cur_period += delta_time - easing_data.cur_period: float = min(easing_data.cur_period, easing_data.end_period) + easing_data.cur_period = min(easing_data.cur_period, easing_data.end_period) if easing_data.end_period == 0: - percent: float = 1.0 - value: EasingData = easing_data.end_value + percent = 1.0 + value = easing_data.end_value else: - percent: float = easing_data.cur_period / easing_data.end_period - value: EasingData = easing(percent, easing_data) + percent = easing_data.cur_period / easing_data.end_period + value = easing(percent, easing_data) done: bool = percent >= 1.0 return done, value From ffedb2839480a346ec2a5829d0ec445179f6ac2b Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 15:10:27 -0700 Subject: [PATCH 08/64] Mics changes bc tests are breaking --- arcade/gui/property.py | 2 +- arcade/math.py | 10 +++++----- arcade/shape_list.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 70ff8c1cd..86dda904a 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,6 +1,6 @@ import sys import traceback -from typing import TypeVar +from typing import TypeVar, Optional, Union from weakref import WeakKeyDictionary, ref diff --git a/arcade/math.py b/arcade/math.py index f45e1f32b..deab59bb4 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -215,16 +215,16 @@ def from_polar(angle, radius: float) -> _Vec2: rads = math.radians(angle) return _Vec2(radius * math.cos(rads), radius * math.sin(rads)) - def __add__(self, other: object) -> _Vec2: + def __add__(self, other: _Vec2) -> _Vec2: return _Vec2(self.x + other.x, self.y + other.y) - def __sub__(self, other: object) -> _Vec2: + def __sub__(self, other: _Vec2) -> _Vec2: return _Vec2(self.x - other.x, self.y - other.y) - def __mul__(self, other: object) -> _Vec2: + def __mul__(self, other: _Vec2) -> _Vec2: return _Vec2(self.x * other.x, self.y * other.y) - def __truediv__(self, other: object) -> _Vec2: + def __truediv__(self, other: _Vec2) -> _Vec2: return _Vec2(self.x / other.x, self.y / other.y) def __iter__(self): @@ -235,7 +235,7 @@ def length(self) -> float: """return the length (magnitude) of the vector""" return math.sqrt(self.x**2 + self.y**2) - def dot(self, other: object) -> float: + def dot(self, other: _Vec2) -> float: return self.x * other.x + self.y * other.y def __repr__(self): diff --git a/arcade/shape_list.py b/arcade/shape_list.py index b50f3a509..2046d5dea 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -734,7 +734,7 @@ def __init__(self) -> None: # The context this shape list belongs to self.ctx = get_window().ctx # List of sprites in the sprite list - self.shape_list = [] + self.shape_list: List[TShape] = [] self.change_x = 0 self.change_y = 0 self._center_x = 0 @@ -742,7 +742,7 @@ def __init__(self) -> None: self._angle = 0 self.program = self.ctx.shape_element_list_program self.batches: Dict[int, _Batch] = OrderedDict() - self.dirties = set() + self.dirties: Set[_Batch] = set() def append(self, item: TShape) -> None: """ @@ -872,7 +872,7 @@ def __iter__(self) -> Iterable[TShape]: """ Return an iterable object of sprites. """ return iter(self.shape_list) - def __getitem__(self, i) -> TShape: + def __getitem__(self, i: int) -> TShape: return self.shape_list[i] From be086d0579d51c8ec8c679c2dfdedef5702f6781 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 24 Apr 2023 15:11:05 -0700 Subject: [PATCH 09/64] . --- arcade/gui/property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 86dda904a..ed699ce8c 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,6 +1,6 @@ import sys import traceback -from typing import TypeVar, Optional, Union +from typing import TypeVar, Optional, Union, Callable from weakref import WeakKeyDictionary, ref From 06b6dddd6a0da2c69856f7950cba95c91641d1b4 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 25 Apr 2023 14:52:45 -0700 Subject: [PATCH 10/64] Changes bc git complained --- arcade/gui/property.py | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index ed699ce8c..0daf1d15c 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,6 +1,6 @@ import sys import traceback -from typing import TypeVar, Optional, Union, Callable +from typing import TypeVar, Optional, Union, Callable, Any from weakref import WeakKeyDictionary, ref @@ -14,7 +14,7 @@ class _Obs: def __init__(self) -> None: self.value = None # This will keep any added listener even if it is not referenced anymore and would be garbage collected - self.listeners = set() + self.listeners: Set[Callable] = set() P = TypeVar("P") @@ -31,14 +31,14 @@ class Property: __slots__ = "name", "default_factory", "obs" name: str - def __init__(self, default: Optional[object]=None, default_factory: callable=None) -> None: + def __init__(self, default: Any=None, default_factory: Callable=None) -> None: if default_factory is None: default_factory = lambda prop, instance: default self.default_factory = default_factory - self.obs = WeakKeyDictionary() + self.obs: WeakKeyDictionary[Any: _Obs] = WeakKeyDictionary() - def _get_obs(self, instance: Optional[object]) -> _Obs: + def _get_obs(self, instance: Any) -> _Obs: obs = self.obs.get(instance) if obs is None: obs = _Obs() @@ -46,17 +46,17 @@ def _get_obs(self, instance: Optional[object]) -> _Obs: self.obs[instance] = obs return obs - def get(self, instance: Optional[object]) -> Optional[object]: + def get(self, instance: Any) -> Any: obs = self._get_obs(instance) return obs.value - def set(self, instance: Optional[object], value: Optional[object]) -> None: + def set(self, instance: Any, value: Any) -> None: obs = self._get_obs(instance) if obs.value != value: obs.value = value self.dispatch(instance, value) - def dispatch(self, instance: Optional[object], value: Optional[object]) -> None: + def dispatch(self, instance: Any, value: Any) -> None: obs = self._get_obs(instance) for listener in obs.listeners: try: @@ -68,7 +68,7 @@ def dispatch(self, instance: Optional[object], value: Optional[object]) -> None: ) traceback.print_exc() - def bind(self, instance: Optional[object], callback: callable) -> None: + def bind(self, instance: Any, callback: Callable) -> None: obs = self._get_obs(instance) # Instance methods are bound methods, which can not be referenced by normal `ref()` # if listeners would be a WeakSet, we would have to add listeners as WeakMethod ourselves into `WeakSet.data`. @@ -77,16 +77,16 @@ def bind(self, instance: Optional[object], callback: callable) -> None: def __set_name__(self, owner, name: str): self.name = name - def __get__(self, instance: Optional[object], owner) -> Optional[object]: + def __get__(self, instance: Any, owner) -> Any: if instance is None: return self return self.get(instance) - def __set__(self, instance: Optional[object], value: Optional[object]) -> None: + def __set__(self, instance: Any, value: Any) -> None: self.set(instance, value) -def bind(instance, property: str, callback: callable) -> None: +def bind(instance, property: str, callback: Callable) -> None: """ Binds a function to the change event of the property. A reference to the function will be kept, so that it will be still invoked, even if it would normally have been garbage collected. @@ -136,21 +136,21 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs): + def pop(self, *largs: list): result = dict.pop(self, *largs) self.dispatch() return result - def popitem(self): + def popitem(self: list): result = dict.popitem(self) self.dispatch() return result - def setdefault(self, *largs) -> None: + def setdefault(self, *largs: list) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs) -> None: + def update(self, *largs: list) -> None: dict.update(self, *largs) self.dispatch() @@ -164,14 +164,14 @@ class DictProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableDict) - def set(self, instance, value: dict) -> None: + def set(self, instance: Any, value: dict) -> None: value = _ObservableDict(self, instance, value) super().set(instance, value) class _ObservableList(list): # Internal class to observe changes inside a native python list. - def __init__(self, prop: Property, instance, *largs) -> None: + def __init__(self, prop: Property, instance: Any, *largs: list) -> None: self.prop: Property = prop self.obj = ref(instance) super().__init__(*largs) @@ -179,25 +179,25 @@ def __init__(self, prop: Property, instance, *largs) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key, value) -> None: + def __setitem__(self, key: Any, value: list) -> None: list.__setitem__(self, key, value) self.dispatch() - def __delitem__(self, key) -> None: + def __delitem__(self, key: Any) -> None: list.__delitem__(self, key) self.dispatch() - def __iadd__(self, *largs): # type: ignore + def __iadd__(self, *largs: list) -> _ObservableList: # type: ignore list.__iadd__(self, *largs) self.dispatch() return self - def __imul__(self, *largs): # type: ignore + def __imul__(self, *largs: list) -> _ObservableList: # type: ignore list.__imul__(self, *largs) self.dispatch() return self - def append(self, *largs) -> None: + def append(self, *largs: list) -> None: list.append(self, *largs) self.dispatch() @@ -205,24 +205,24 @@ def clear(self) -> None: list.clear(self) self.dispatch() - def remove(self, *largs) -> None: + def remove(self, *largs: list) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs) -> None: + def insert(self, *largs: list) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs) -> None: + def pop(self, *largs: list) -> None: result = list.pop(self, *largs) self.dispatch() return result - def extend(self, *largs) -> None: + def extend(self, *largs: list) -> None: list.extend(self, *largs) self.dispatch() - def sort(self, **kwargs) -> None: + def sort(self, **kwargs: dict) -> None: list.sort(self, **kwargs) self.dispatch() @@ -240,6 +240,6 @@ class ListProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableList) - def set(self, instance, value: dict) -> None: + def set(self, instance: Any, value: dict) -> None: value = _ObservableList(self, instance, value) # type: ignore super().set(instance, value) From 171af9bd5dd92ad57bfdc2d1acee792e924eb95b Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 25 Apr 2023 15:23:37 -0700 Subject: [PATCH 11/64] Fixes problems in 4 files --- arcade/application.py | 6 +++--- arcade/easing.py | 2 +- arcade/gui/property.py | 4 ++-- arcade/shape_list.py | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 3f30a5a33..3387092ae 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -11,7 +11,7 @@ import pyglet.gl as gl from pyglet.canvas.base import ScreenMode -from pyglet.window import MouseCursor, DefaultMouseCursor +from pyglet.window import MouseCursor, DefaultMouseCursor, XlibMouseCursor import arcade from arcade import get_display_size @@ -20,7 +20,7 @@ from arcade.color import TRANSPARENT_BLACK from arcade.context import ArcadeContext from arcade.types import Color, RGBA255, RGBA255OrNormalized -from arcade import SectionManager +from arcade import SectionManager, Section from arcade.utils import is_raspberry_pi LOG = logging.getLogger(__name__) @@ -958,7 +958,7 @@ def has_sections(self) -> bool: else: return self.section_manager.has_sections - def add_section(self, section: Optional["Section"], at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: + def add_section(self, section: Optional[Section], at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: """ Adds a section to the view Section Manager. diff --git a/arcade/easing.py b/arcade/easing.py index 32b669602..e3f84813d 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -177,7 +177,7 @@ def ease_angle(start_angle: float, end_angle: float, *, return easing_data -def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, EasingData]: +def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, float]: """ Update angle easing. """ diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 0daf1d15c..614fdb92e 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -218,11 +218,11 @@ def pop(self, *largs: list) -> None: self.dispatch() return result - def extend(self, *largs: list) -> None: + def extend(self, *largs: Iterable[Any, ...]) -> None: list.extend(self, *largs) self.dispatch() - def sort(self, **kwargs: dict) -> None: + def sort(self, **kwargs: Dict) -> None: list.sort(self, **kwargs) self.dispatch() diff --git a/arcade/shape_list.py b/arcade/shape_list.py index 2046d5dea..8e473eebc 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -68,8 +68,8 @@ def __init__( self.data = array("f", [c for a in zip(self.points, self.colors) for b in a for c in b]) self.vertices = len(points) - self.geometry = None - self.buffer = None + self.geometry: ["Geometry"] = None + self.buffer: Optional[ArcadeContext] = None def _init_geometry(self) -> None: # NOTE: When drawing a single shape we're not using an index buffer @@ -735,11 +735,11 @@ def __init__(self) -> None: self.ctx = get_window().ctx # List of sprites in the sprite list self.shape_list: List[TShape] = [] - self.change_x = 0 - self.change_y = 0 - self._center_x = 0 - self._center_y = 0 - self._angle = 0 + self.change_x: float = 0 + self.change_y: float = 0 + self._center_x: float = 0 + self._center_y: float = 0 + self._angle: float = 0 self.program = self.ctx.shape_element_list_program self.batches: Dict[int, _Batch] = OrderedDict() self.dirties: Set[_Batch] = set() From 9623b62fe2a829eaf86dc6e4555d0607fd39772c Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Wed, 26 Apr 2023 08:49:49 -0700 Subject: [PATCH 12/64] Attempt to fix git again --- arcade/application.py | 6 ++--- arcade/gui/property.py | 42 +++++++++++++++++++------------ arcade/math.py | 4 +-- arcade/shape_list.py | 1 + arcade/sprite_list/sprite_list.py | 10 ++++---- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 3387092ae..116cb9c84 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -11,7 +11,7 @@ import pyglet.gl as gl from pyglet.canvas.base import ScreenMode -from pyglet.window import MouseCursor, DefaultMouseCursor, XlibMouseCursor +from pyglet.window import MouseCursor, XlibMouseCursor, DefaultMouseCursor import arcade from arcade import get_display_size @@ -868,7 +868,7 @@ def set_exclusive_keyboard(self, exclusive: bool=True) -> None: """ Capture all keyboard input. """ super().set_exclusive_keyboard(exclusive) - def get_system_mouse_cursor(self, name: str) -> Optional[DefualtMouseCursor, XlibMouseCursor]: + def get_system_mouse_cursor(self, name: str) -> Optional[DefaultMouseCursor, XlibMouseCursor]: """ Get the system mouse cursor """ return super().get_system_mouse_cursor(name) @@ -958,7 +958,7 @@ def has_sections(self) -> bool: else: return self.section_manager.has_sections - def add_section(self, section: Optional[Section], at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: + def add_section(self, section: Section, at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: """ Adds a section to the view Section Manager. diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 614fdb92e..af8c24995 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,6 +1,16 @@ import sys import traceback -from typing import TypeVar, Optional, Union, Callable, Any +from typing import ( + TypeVar, + Optional, + Union, + Callable, + Any, + Iterable, + Dict, + List, + Set +) from weakref import WeakKeyDictionary, ref @@ -31,7 +41,7 @@ class Property: __slots__ = "name", "default_factory", "obs" name: str - def __init__(self, default: Any=None, default_factory: Callable=None) -> None: + def __init__(self, default: Any=None, default_factory: Optional[Callable]=None) -> None: if default_factory is None: default_factory = lambda prop, instance: default @@ -136,21 +146,21 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs: list): + def pop(self, *largs: List): result = dict.pop(self, *largs) self.dispatch() return result - def popitem(self: list): + def popitem(self: List): result = dict.popitem(self) self.dispatch() return result - def setdefault(self, *largs: list) -> None: + def setdefault(self, *largs: List) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: list) -> None: + def update(self, *largs: List) -> None: dict.update(self, *largs) self.dispatch() @@ -164,14 +174,14 @@ class DictProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableDict) - def set(self, instance: Any, value: dict) -> None: + def set(self, instance: Any, value: Dict) -> None: value = _ObservableDict(self, instance, value) super().set(instance, value) class _ObservableList(list): # Internal class to observe changes inside a native python list. - def __init__(self, prop: Property, instance: Any, *largs: list) -> None: + def __init__(self, prop: Property, instance: Any, *largs: List) -> None: self.prop: Property = prop self.obj = ref(instance) super().__init__(*largs) @@ -179,7 +189,7 @@ def __init__(self, prop: Property, instance: Any, *largs: list) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Any, value: list) -> None: + def __setitem__(self, key: Any, value: List) -> None: list.__setitem__(self, key, value) self.dispatch() @@ -187,17 +197,17 @@ def __delitem__(self, key: Any) -> None: list.__delitem__(self, key) self.dispatch() - def __iadd__(self, *largs: list) -> _ObservableList: # type: ignore + def __iadd__(self, *largs: List) -> _ObservableList: # type: ignore list.__iadd__(self, *largs) self.dispatch() return self - def __imul__(self, *largs: list) -> _ObservableList: # type: ignore + def __imul__(self, *largs: List) -> _ObservableList: # type: ignore list.__imul__(self, *largs) self.dispatch() return self - def append(self, *largs: list) -> None: + def append(self, *largs: List) -> None: list.append(self, *largs) self.dispatch() @@ -205,15 +215,15 @@ def clear(self) -> None: list.clear(self) self.dispatch() - def remove(self, *largs: list) -> None: + def remove(self, *largs: List) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs: list) -> None: + def insert(self, *largs: List) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs: list) -> None: + def pop(self, *largs: List) -> None: result = list.pop(self, *largs) self.dispatch() return result @@ -240,6 +250,6 @@ class ListProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableList) - def set(self, instance: Any, value: dict) -> None: + def set(self, instance: Any, value: Dict) -> None: value = _ObservableList(self, instance, value) # type: ignore super().set(instance, value) diff --git a/arcade/math.py b/arcade/math.py index deab59bb4..9ab171516 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -190,8 +190,8 @@ def rand_vec_magnitude( :param hi_magnitude: The higher magnitude :return: A random vector """ - mag = random.uniform(lo_magnitude, hi_magnitude) - vel = _Vec2.from_polar(angle, mag) + mag: float = random.uniform(lo_magnitude, hi_magnitude) + vel: _Vec2 = _Vec2.from_polar(angle, mag) return vel.as_tuple() diff --git a/arcade/shape_list.py b/arcade/shape_list.py index 8e473eebc..e1acddd61 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -12,6 +12,7 @@ from array import array from typing import ( Dict, + Set, List, Tuple, Iterable, diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index aacaac34d..002a02878 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -134,11 +134,11 @@ def __init__( # Index buffer self._sprite_index_data = array("i", [0] * self._idx_capacity) - self._sprite_pos_buf = None - self._sprite_size_buf = None - self._sprite_angle_buf = None - self._sprite_color_buf = None - self._sprite_texture_buf = None + self._sprite_pos_buf: Optional[Buffer] = None + self._sprite_size_buf: Optional[Buffer] = None + self._sprite_angle_buf: Optional[Buffer] = None + self._sprite_color_buf: Optional[Buffer] = None + self._sprite_texture_buf: Optional[Buffer] = None # Index buffer self._sprite_index_buf = None From a432ca6480b5b610b500bb139c0db2f04aa75b4e Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Thu, 27 Apr 2023 08:49:15 -0700 Subject: [PATCH 13/64] type hint problems in property.py --- arcade/application.py | 4 ++-- arcade/gui/property.py | 22 +++++++++++----------- arcade/shape_list.py | 6 ++++-- arcade/sprite_list/sprite_list.py | 6 +++--- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 116cb9c84..8624388c3 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -11,7 +11,7 @@ import pyglet.gl as gl from pyglet.canvas.base import ScreenMode -from pyglet.window import MouseCursor, XlibMouseCursor, DefaultMouseCursor +from pyglet.window import MouseCursor import arcade from arcade import get_display_size @@ -868,7 +868,7 @@ def set_exclusive_keyboard(self, exclusive: bool=True) -> None: """ Capture all keyboard input. """ super().set_exclusive_keyboard(exclusive) - def get_system_mouse_cursor(self, name: str) -> Optional[DefaultMouseCursor, XlibMouseCursor]: + def get_system_mouse_cursor(self, name: str) -> Optional[MouseCursor]: """ Get the system mouse cursor """ return super().get_system_mouse_cursor(name) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index af8c24995..2f9a411db 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -46,7 +46,7 @@ def __init__(self, default: Any=None, default_factory: Optional[Callable]=None) default_factory = lambda prop, instance: default self.default_factory = default_factory - self.obs: WeakKeyDictionary[Any: _Obs] = WeakKeyDictionary() + self.obs: WeakKeyDictionary[Any, _Obs] = WeakKeyDictionary() def _get_obs(self, instance: Any) -> _Obs: obs = self.obs.get(instance) @@ -87,7 +87,7 @@ def bind(self, instance: Any, callback: Callable) -> None: def __set_name__(self, owner, name: str): self.name = name - def __get__(self, instance: Any, owner) -> Any: + def __get__(self, instance: Any, owner) -> Union[Property, Any]: if instance is None: return self return self.get(instance) @@ -146,21 +146,21 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs: List): + def pop(self, *largs: List[Any]) -> Any: result = dict.pop(self, *largs) self.dispatch() return result - def popitem(self: List): + def popitem(self) -> Tuple[Any, Any]: result = dict.popitem(self) self.dispatch() return result - def setdefault(self, *largs: List) -> None: + def setdefault(self, *largs: List[Any]) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: List) -> None: + def update(self, *largs: List[Any]) -> None: dict.update(self, *largs) self.dispatch() @@ -189,7 +189,7 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Any, value: List) -> None: + def __setitem__(self, key: Any, value: List[Any]) -> None: list.__setitem__(self, key, value) self.dispatch() @@ -202,7 +202,7 @@ def __iadd__(self, *largs: List) -> _ObservableList: # type: ignore self.dispatch() return self - def __imul__(self, *largs: List) -> _ObservableList: # type: ignore + def __imul__(self, *largs: List[Any]) -> _ObservableList: # type: ignore list.__imul__(self, *largs) self.dispatch() return self @@ -219,16 +219,16 @@ def remove(self, *largs: List) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs: List) -> None: + def insert(self, *largs: List[Any]) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs: List) -> None: + def pop(self, *largs: List[Any]) -> Any: result = list.pop(self, *largs) self.dispatch() return result - def extend(self, *largs: Iterable[Any, ...]) -> None: + def extend(self, *largs: List) -> None: list.extend(self, *largs) self.dispatch() diff --git a/arcade/shape_list.py b/arcade/shape_list.py index e1acddd61..7f58bcfd5 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -29,6 +29,8 @@ from arcade import get_window, get_points_for_thick_line from arcade.gl import BufferDescription from arcade.gl import Program +from ..types import BufferProtocol +from .vertex_array import Geometry from arcade import ArcadeContext from .math import rotate_point @@ -69,8 +71,8 @@ def __init__( self.data = array("f", [c for a in zip(self.points, self.colors) for b in a for c in b]) self.vertices = len(points) - self.geometry: ["Geometry"] = None - self.buffer: Optional[ArcadeContext] = None + self.geometry: [Geometry] = None + self.buffer: Optional[BufferProtocol] = None def _init_geometry(self) -> None: # NOTE: When drawing a single shape we're not using an index buffer diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 002a02878..381feebd9 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -961,11 +961,11 @@ def draw(self, *, filter: Optional["gl filter"]=None, pixelated: bool=False, ble """ Draw this list of sprites. - :param filter: Optional parameter to set OpenGL filter, such as + :param Optional[gl filter] filter: Optional parameter to set OpenGL filter, such as `gl.GL_NEAREST` to avoid smoothing. - :param pixelated: ``True`` for pixelated and ``False`` for smooth interpolation. + :param bool pixelated: ``True`` for pixelated and ``False`` for smooth interpolation. Shortcut for setting filter=GL_NEAREST. - :param blend_function: Optional parameter to set the OpenGL blend function used for drawing the + :param Optional[gl blend function] blend_function: Optional parameter to set the OpenGL blend function used for drawing the sprite list, such as 'arcade.Window.ctx.BLEND_ADDITIVE' or 'arcade.Window.ctx.BLEND_DEFAULT' """ if len(self.sprite_list) == 0 or not self._visible or self.alpha_normalized == 0.0: From 5294ea145e8c24c053cd1c6eb806e0cda2907e3e Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Thu, 27 Apr 2023 19:28:36 -0700 Subject: [PATCH 14/64] attempts to fix property.py --- arcade/gui/property.py | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 2f9a411db..6ab9a96cc 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,15 +1,18 @@ import sys import traceback from typing import ( - TypeVar, - Optional, - Union, - Callable, - Any, - Iterable, - Dict, - List, - Set + TypeVar, + Optional, + Union, + Tuple, + Callable, + Any, + Iterable, + Dict, + List, + Set, + MutableMapping, + MutableSequence ) from weakref import WeakKeyDictionary, ref @@ -87,7 +90,7 @@ def bind(self, instance: Any, callback: Callable) -> None: def __set_name__(self, owner, name: str): self.name = name - def __get__(self, instance: Any, owner) -> Union[Property, Any]: + def __get__(self, instance: Property, owner) -> Property: if instance is None: return self return self.get(instance) @@ -146,7 +149,7 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs: List[Any]) -> Any: + def pop(self, *largs: MutableMapping) -> Any: result = dict.pop(self, *largs) self.dispatch() return result @@ -156,11 +159,11 @@ def popitem(self) -> Tuple[Any, Any]: self.dispatch() return result - def setdefault(self, *largs: List[Any]) -> None: + def setdefault(self, *largs: MutableMapping) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: List[Any]) -> None: + def update(self, *largs: MutableMapping) -> None: dict.update(self, *largs) self.dispatch() @@ -189,7 +192,7 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Any, value: List[Any]) -> None: + def __setitem__(self, key: Any, value: MutableSequence) -> None: list.__setitem__(self, key, value) self.dispatch() @@ -202,12 +205,12 @@ def __iadd__(self, *largs: List) -> _ObservableList: # type: ignore self.dispatch() return self - def __imul__(self, *largs: List[Any]) -> _ObservableList: # type: ignore + def __imul__(self, *largs: int) -> _ObservableList: # type: ignore list.__imul__(self, *largs) self.dispatch() return self - def append(self, *largs: List) -> None: + def append(self, *largs: Any) -> None: list.append(self, *largs) self.dispatch() @@ -215,24 +218,24 @@ def clear(self) -> None: list.clear(self) self.dispatch() - def remove(self, *largs: List) -> None: + def remove(self, *largs: Any) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs: List[Any]) -> None: + def insert(self, *largs: int) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs: List[Any]) -> Any: + def pop(self, *largs: int) -> Any: result = list.pop(self, *largs) self.dispatch() return result - def extend(self, *largs: List) -> None: + def extend(self, *largs: Iterable[Any]) -> None: list.extend(self, *largs) self.dispatch() - def sort(self, **kwargs: Dict) -> None: + def sort(self, **kwargs: Callable) -> None: list.sort(self, **kwargs) self.dispatch() @@ -250,6 +253,6 @@ class ListProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableList) - def set(self, instance: Any, value: Dict) -> None: + def set(self, instance: Any, value: List) -> None: value = _ObservableList(self, instance, value) # type: ignore super().set(instance, value) From 5b0d1f0ffb9fe5d620a8a4396e8a01f79a47f334 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Thu, 27 Apr 2023 19:48:32 -0700 Subject: [PATCH 15/64] I was misunderstanding the test error messages --- arcade/gui/property.py | 14 +++++++------- arcade/shape_list.py | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 6ab9a96cc..bfcc1be69 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -90,7 +90,7 @@ def bind(self, instance: Any, callback: Callable) -> None: def __set_name__(self, owner, name: str): self.name = name - def __get__(self, instance: Property, owner) -> Property: + def __get__(self, instance: Any, owner) -> Union[Property, Any]: if instance is None: return self return self.get(instance) @@ -149,7 +149,7 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs: MutableMapping) -> Any: + def pop(self, *largs: Union[Dict[Any, Any], MutableMapping[Any, Any]]) -> Any: result = dict.pop(self, *largs) self.dispatch() return result @@ -159,11 +159,11 @@ def popitem(self) -> Tuple[Any, Any]: self.dispatch() return result - def setdefault(self, *largs: MutableMapping) -> None: + def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: MutableMapping) -> None: + def update(self, *largs: Any) -> None: dict.update(self, *largs) self.dispatch() @@ -192,7 +192,7 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Any, value: MutableSequence) -> None: + def __setitem__(self, key: Union[int, slice], value: Any) -> None: list.__setitem__(self, key, value) self.dispatch() @@ -222,7 +222,7 @@ def remove(self, *largs: Any) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs: int) -> None: + def insert(self, *largs: Any) -> None: list.insert(self, *largs) self.dispatch() @@ -235,7 +235,7 @@ def extend(self, *largs: Iterable[Any]) -> None: list.extend(self, *largs) self.dispatch() - def sort(self, **kwargs: Callable) -> None: + def sort(self, **kwargs) -> None: list.sort(self, **kwargs) self.dispatch() diff --git a/arcade/shape_list.py b/arcade/shape_list.py index 7f58bcfd5..cc2f703d1 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -25,11 +25,10 @@ import pyglet.gl as gl -from arcade.types import Color, Point, PointList, RGBA255 +from arcade.types import Color, Point, PointList, RGBA255, BufferProtocol from arcade import get_window, get_points_for_thick_line from arcade.gl import BufferDescription from arcade.gl import Program -from ..types import BufferProtocol from .vertex_array import Geometry from arcade import ArcadeContext From 211f6a24b0f40734557d9576a539ced563a42336 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Thu, 27 Apr 2023 19:59:33 -0700 Subject: [PATCH 16/64] . --- arcade/application.py | 4 ++-- arcade/gui/property.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 8624388c3..c08114d85 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -5,7 +5,7 @@ import logging import os import time -from typing import Tuple, Optional +from typing import List, Tuple, Optional import pyglet @@ -783,7 +783,7 @@ def hide_view(self) -> None: def _create(self) -> None: super()._create() - def _recreate(self, changes: [str]) -> None: + def _recreate(self, changes: List[str]) -> None: super()._recreate(changes) def flip(self) -> None: diff --git a/arcade/gui/property.py b/arcade/gui/property.py index bfcc1be69..a7f2a6d9d 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -149,7 +149,7 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs: Union[Dict[Any, Any], MutableMapping[Any, Any]]) -> Any: + def pop(self, *largs: Any) -> Any: result = dict.pop(self, *largs) self.dispatch() return result @@ -163,7 +163,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Any) -> None: + def update(self, *largs: Iterable) -> None: dict.update(self, *largs) self.dispatch() From 3698b0f7c95198dc47bce3cab3742ffdd2190db9 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 28 Apr 2023 09:55:50 -0700 Subject: [PATCH 17/64] Attempt to fix property --- arcade/gui/property.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index a7f2a6d9d..f7eebc73d 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -163,7 +163,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Iterable) -> None: + def update(self, *largs: Union[Iterable, MutableMapping]) -> None: dict.update(self, *largs) self.dispatch() @@ -192,7 +192,7 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Union[int, slice], value: Any) -> None: + def __setitem__(self, key: Union[int, slice, list], value: Any) -> None: list.__setitem__(self, key, value) self.dispatch() From 51a15ebbfa50712c59bbbcdb021d1ee742cbb2b2 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 28 Apr 2023 10:38:38 -0700 Subject: [PATCH 18/64] . --- arcade/gui/property.py | 2 +- arcade/shape_list.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index f7eebc73d..2ef0553aa 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -90,7 +90,7 @@ def bind(self, instance: Any, callback: Callable) -> None: def __set_name__(self, owner, name: str): self.name = name - def __get__(self, instance: Any, owner) -> Union[Property, Any]: + def __get__(self, instance: Any, owner) -> Any: if instance is None: return self return self.get(instance) diff --git a/arcade/shape_list.py b/arcade/shape_list.py index cc2f703d1..26c8af43f 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -27,9 +27,7 @@ from arcade.types import Color, Point, PointList, RGBA255, BufferProtocol from arcade import get_window, get_points_for_thick_line -from arcade.gl import BufferDescription -from arcade.gl import Program -from .vertex_array import Geometry +from arcade.gl import BufferDescription, Program, Geometry from arcade import ArcadeContext from .math import rotate_point @@ -70,8 +68,8 @@ def __init__( self.data = array("f", [c for a in zip(self.points, self.colors) for b in a for c in b]) self.vertices = len(points) - self.geometry: [Geometry] = None - self.buffer: Optional[BufferProtocol] = None + self.geometry: Optional[Geometry] = None + self.buffer: Optional[Buffer] = None def _init_geometry(self) -> None: # NOTE: When drawing a single shape we're not using an index buffer From 71ef4b2fa9063ccac19c08f92ac1cfa63b85c1ca Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 28 Apr 2023 10:47:58 -0700 Subject: [PATCH 19/64] . --- arcade/gui/property.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 2ef0553aa..44d3c8515 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -163,7 +163,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Union[Iterable, MutableMapping]) -> None: + def update(self, *largs: Union[Iterable[Tuple], MutableMapping]) -> None: dict.update(self, *largs) self.dispatch() @@ -192,7 +192,7 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Union[int, slice, list], value: Any) -> None: + def __setitem__(self, key: Union[int, slice], value: Any) -> None: list.__setitem__(self, key, value) self.dispatch() From 7de2f683d23562275d15bf649dd33b2a369f930b Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 28 Apr 2023 20:10:06 -0700 Subject: [PATCH 20/64] Check changes in mixins.py --- arcade/gui/property.py | 6 +++--- arcade/sprite/animated.py | 4 ++-- arcade/sprite/mixins.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 44d3c8515..747a6d982 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -12,7 +12,7 @@ List, Set, MutableMapping, - MutableSequence + Mapping, ) from weakref import WeakKeyDictionary, ref @@ -163,7 +163,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Union[Iterable[Tuple], MutableMapping]) -> None: + def update(self, *largs: Union[Iterable[Tuple], Mapping]) -> None: dict.update(self, *largs) self.dispatch() @@ -192,7 +192,7 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key: Union[int, slice], value: Any) -> None: + def __setitem__(self, key, value: Any) -> None: list.__setitem__(self, key, value) self.dispatch() diff --git a/arcade/sprite/animated.py b/arcade/sprite/animated.py index 5eec30df2..007c97996 100644 --- a/arcade/sprite/animated.py +++ b/arcade/sprite/animated.py @@ -1,6 +1,6 @@ import dataclasses import math -from typing import List +from typing import List, Optional from .sprite import Sprite from arcade import Texture @@ -35,7 +35,7 @@ class AnimatedTimeBasedSprite(Sprite): """ def __init__( self, - path_or_texture: PathOrTexture = None, + path_or_texture: Optional[PathOrTexture] = None, center_x: float = 0.0, center_y: float = 0.0, scale: float = 1.0, diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 7277afbe6..3cb5864b9 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -10,7 +10,7 @@ class PyMunk: "max_vertical_velocity", ) - def __init__(self): + def __init__(self) -> None: self.damping = None self.gravity = None self.max_velocity = None @@ -20,10 +20,10 @@ def __init__(self): class PymunkMixin: - def __init__(self): + def __init__(self) -> None: self.pymunk = PyMunk() self.force = [0.0, 0.0] - def pymunk_moved(self, physics_engine, dx, dy, d_angle): + def pymunk_moved(self, physics_engine, dx: float, dy: float, d_angle: float) -> None: """Called by the pymunk physics engine if this sprite moves.""" pass From 7873b18bdb24bbb583781b160ab992506d9d1b50 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 2 May 2023 18:03:59 -0700 Subject: [PATCH 21/64] Address no slots in View Fixes https://github.com/pythonarcade/arcade/issues/1743 --- arcade/application.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arcade/application.py b/arcade/application.py index c08114d85..663c211e6 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -935,7 +935,13 @@ class View: """ Support different views/screens in a window. """ - + __slots__ = ( + "window", + "key", + "_section_manager", + "section_manager", + "", + ) def __init__(self, window: Optional[Window] = None) -> None: From f50d5e7607666025ca29c7ebff705b5e84ad792e Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 2 May 2023 18:15:02 -0700 Subject: [PATCH 22/64] Partially added __slots__ Pyglet doesn't have __slots__ so I didn't know all the variables --- arcade/application.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 663c211e6..e5f4773af 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -77,7 +77,26 @@ class Window(pyglet.window.Window): :param bool enable_polling: Enabled input polling capability. This makes the ``keyboard`` and ``mouse`` \ attributes available for use. """ - + slots = ( + "headless", + "_draw_rate", + "_update_rate", + "_current_view", + "current_view", + "_current_camera", + "current_camera", + "textbox_time", + "key", + "flip_count", + "static_display", + "_ctx", + "ctx", + "_background_color", + "background_color", + "keyboard", + "mouse", + "_resizable", + ) def __init__( self, width: int = 800, @@ -940,7 +959,6 @@ class View: "key", "_section_manager", "section_manager", - "", ) def __init__(self, window: Optional[Window] = None) -> None: From 4b3789d5a4462cd07e7800170f73a559fbde96e2 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 2 May 2023 18:29:00 -0700 Subject: [PATCH 23/64] Role back __slots__ --- arcade/application.py | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index e5f4773af..cd3f559ab 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -77,26 +77,7 @@ class Window(pyglet.window.Window): :param bool enable_polling: Enabled input polling capability. This makes the ``keyboard`` and ``mouse`` \ attributes available for use. """ - slots = ( - "headless", - "_draw_rate", - "_update_rate", - "_current_view", - "current_view", - "_current_camera", - "current_camera", - "textbox_time", - "key", - "flip_count", - "static_display", - "_ctx", - "ctx", - "_background_color", - "background_color", - "keyboard", - "mouse", - "_resizable", - ) + def __init__( self, width: int = 800, @@ -954,12 +935,7 @@ class View: """ Support different views/screens in a window. """ - __slots__ = ( - "window", - "key", - "_section_manager", - "section_manager", - ) + def __init__(self, window: Optional[Window] = None) -> None: From 8563913f65d868201c365abdb80bff569990d4ca Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 5 May 2023 19:55:04 -0700 Subject: [PATCH 24/64] . --- arcade/pymunk_physics_engine.py | 6 +++--- arcade/sprite/mixins.py | 11 ++++++----- arcade/sprite_list/sprite_list.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index a28cec77b..d69453112 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -62,9 +62,9 @@ def add_sprite(self, body_type: int = DYNAMIC, damping: Optional[float] = None, gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]] = None, - max_velocity: Optional[int] = None, - max_horizontal_velocity: Optional[int] = None, - max_vertical_velocity: Optional[int] = None, + max_velocity: Optional[float] = None, + max_horizontal_velocity: Optional[float] = None, + max_vertical_velocity: Optional[float] = None, radius: float = 0, collision_type: Optional[str] = "default", ): diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 3cb5864b9..99a454338 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -11,14 +11,15 @@ class PyMunk: ) def __init__(self) -> None: - self.damping = None - self.gravity = None - self.max_velocity = None - self.max_horizontal_velocity = None - self.max_vertical_velocity = None + self.damping: Optional[float] = None + self.gravity: Optional[float] = None + self.max_velocity: Optional[float] = None + self.max_horizontal_velocity: Optional[float] = None + self.max_vertical_velocity: Optional[float] = None class PymunkMixin: + """Sprite uses this to add pymunk""" def __init__(self) -> None: self.pymunk = PyMunk() diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 381feebd9..d7ee546f7 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -957,7 +957,7 @@ def initialize(self): """ self._init_deferred() - def draw(self, *, filter: Optional["gl filter"]=None, pixelated: bool=False, blend_function: Optional["gl blend function"]=None) -> None: + def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, blend_function: Optional[int]=None) -> None: """ Draw this list of sprites. From 18c7c2ce8a7661fb8d8ee7614bb19aaa8e6e5802 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 5 May 2023 19:58:39 -0700 Subject: [PATCH 25/64] . --- arcade/gui/property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 747a6d982..96abbd21e 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -163,7 +163,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Union[Iterable[Tuple], Mapping]) -> None: + def update(self, *largs: Union[Iterable[Dict], Dict]) -> None: dict.update(self, *largs) self.dispatch() From 8d4fdd07d806bd28cd0a9704857e22fe172d540e Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 11:21:33 -0700 Subject: [PATCH 26/64] (View) --- arcade/sprite/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 99a454338..0fabc4738 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,4 +1,4 @@ - +from typing import Optional class PyMunk: """Object used to hold pymunk info for a sprite.""" From 545fde1f34266f3454b482e0b8cacdd9315c0030 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 11:23:20 -0700 Subject: [PATCH 27/64] . --- arcade/gui/property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 96abbd21e..ab70e0bbd 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -163,7 +163,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Union[Iterable[Dict], Dict]) -> None: + def update(self, *largs: Union[Iterable[MutableMapping], MutableMapping]) -> None: dict.update(self, *largs) self.dispatch() From bfc4bc82edd86b3561ad730cc65a077c5fa718d7 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 11:27:06 -0700 Subject: [PATCH 28/64] . --- arcade/gui/property.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index ab70e0bbd..0746573e0 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -163,7 +163,14 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs: Union[Iterable[MutableMapping], MutableMapping]) -> None: + @overload + def update(self, __m: Mapping, **kwargs: Any) -> None: ... + @overload + def update(self, __m: Iterable[Tuple[Any, Any]], **kwargs: Any) -> None: ... + @overload + def update(self, **kwargs: Any) -> None: ... + + def update(self, *largs) -> None: dict.update(self, *largs) self.dispatch() From cb7476455cec9916ca4df27987779d597b7e79ca Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 11:28:45 -0700 Subject: [PATCH 29/64] . --- arcade/gui/property.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 0746573e0..4c2a2653b 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -12,7 +12,8 @@ List, Set, MutableMapping, - Mapping, + Mapping, + overload ) from weakref import WeakKeyDictionary, ref @@ -169,7 +170,7 @@ def update(self, __m: Mapping, **kwargs: Any) -> None: ... def update(self, __m: Iterable[Tuple[Any, Any]], **kwargs: Any) -> None: ... @overload def update(self, **kwargs: Any) -> None: ... - + def update(self, *largs) -> None: dict.update(self, *largs) self.dispatch() From 3d52f73ba79958f795023ed4aec43e9620ef41c6 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 11:32:37 -0700 Subject: [PATCH 30/64] . --- arcade/gui/property.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 4c2a2653b..c2c3230bb 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,7 +1,6 @@ import sys import traceback from typing import ( - TypeVar, Optional, Union, Tuple, @@ -11,9 +10,9 @@ Dict, List, Set, - MutableMapping, Mapping, - overload + overload, + SupportsIndex ) from weakref import WeakKeyDictionary, ref @@ -31,9 +30,6 @@ def __init__(self) -> None: self.listeners: Set[Callable] = set() -P = TypeVar("P") - - class Property: """ An observable property which triggers observers when changed. @@ -234,7 +230,7 @@ def insert(self, *largs: Any) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs: int) -> Any: + def pop(self, *largs: SupportsIndex) -> Any: result = list.pop(self, *largs) self.dispatch() return result From 5c6e5d613da65c2ae87953a4263db41bde115256 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 12:05:04 -0700 Subject: [PATCH 31/64] . --- arcade/gui/property.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index c2c3230bb..ebae28ff0 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -160,13 +160,6 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - @overload - def update(self, __m: Mapping, **kwargs: Any) -> None: ... - @overload - def update(self, __m: Iterable[Tuple[Any, Any]], **kwargs: Any) -> None: ... - @overload - def update(self, **kwargs: Any) -> None: ... - def update(self, *largs) -> None: dict.update(self, *largs) self.dispatch() From f581cbfba636e3b98333892db500001429caed9c Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 12:14:19 -0700 Subject: [PATCH 32/64] . --- arcade/pymunk_physics_engine.py | 2 +- arcade/sprite/mixins.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index b952ea85e..acb13e6d8 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -50,7 +50,7 @@ class PymunkPhysicsEngine: KINEMATIC = pymunk.Body.KINEMATIC MOMENT_INF = float('inf') - def __init__(self, gravity=(0, 0), damping: float = 1.0, maximum_incline_on_ground: float = 0.708): + def __init__(self, gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]]=(0, 0), damping: float = 1.0, maximum_incline_on_ground: float = 0.708): # -- Pymunk self.space = pymunk.Space() self.space.gravity = gravity diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 0fabc4738..bf0a60e3b 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -12,7 +12,7 @@ class PyMunk: def __init__(self) -> None: self.damping: Optional[float] = None - self.gravity: Optional[float] = None + self.gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]] = None self.max_velocity: Optional[float] = None self.max_horizontal_velocity: Optional[float] = None self.max_vertical_velocity: Optional[float] = None From 2d44801193b532c250b6eeb2cf9ed1ea36a454e7 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 12:23:19 -0700 Subject: [PATCH 33/64] . --- arcade/gui/property.py | 2 +- arcade/sprite/mixins.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index ebae28ff0..2ff1f16ee 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -160,7 +160,7 @@ def setdefault(self, *largs: Any) -> None: dict.setdefault(self, *largs) self.dispatch() - def update(self, *largs) -> None: + def update(self, *largs): dict.update(self, *largs) self.dispatch() diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index bf0a60e3b..9221e4b5c 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Optional, Union class PyMunk: """Object used to hold pymunk info for a sprite.""" From a2097f1b7616613d720ef1350ceedb904a921ad5 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 12:25:46 -0700 Subject: [PATCH 34/64] . --- arcade/sprite/mixins.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 9221e4b5c..2c9c95a26 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,4 +1,8 @@ -from typing import Optional, Union +from typing import Optional, Union, TYPE_CHECKING + +if TYPE_CHECKING: + from arcade import Vec2 + from pymunk import Vec2d class PyMunk: """Object used to hold pymunk info for a sprite.""" @@ -12,7 +16,7 @@ class PyMunk: def __init__(self) -> None: self.damping: Optional[float] = None - self.gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]] = None + self.gravity: Optional[Union[Vec2d, Tuple[float, float], Vec2]] = None self.max_velocity: Optional[float] = None self.max_horizontal_velocity: Optional[float] = None self.max_vertical_velocity: Optional[float] = None From 30b5b2657ef1267f266f59bdcc2083af2f7d5c83 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 15:30:32 -0700 Subject: [PATCH 35/64] Add imports to mixins --- arcade/sprite/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 2c9c95a26..84c1083a1 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,4 +1,4 @@ -from typing import Optional, Union, TYPE_CHECKING +from typing import Optional, Union, Tuple, TYPE_CHECKING if TYPE_CHECKING: from arcade import Vec2 From 9ee32fbda464441c9050acc8d5835cd1244bc693 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 15:37:56 -0700 Subject: [PATCH 36/64] Change import in mixins --- arcade/sprite/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index 84c1083a1..d30529ad6 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,8 +1,8 @@ from typing import Optional, Union, Tuple, TYPE_CHECKING if TYPE_CHECKING: - from arcade import Vec2 from pymunk import Vec2d + from pyglet.math import Vec2 class PyMunk: """Object used to hold pymunk info for a sprite.""" From b8ab035f566c39fbfe350576d1b9a67db6044761 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 6 May 2023 15:39:35 -0700 Subject: [PATCH 37/64] Fix shape_list.py --- arcade/shape_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/shape_list.py b/arcade/shape_list.py index 68f8d7c41..3ad0df3b6 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -27,7 +27,7 @@ from arcade.types import Color, Point, PointList, RGBA255, BufferProtocol from arcade import get_window, get_points_for_thick_line -from arcade.gl import BufferDescription, Program, Geometry +from arcade.gl import BufferDescription, Program, Geometry, Buffer from arcade import ArcadeContext from .math import rotate_point From b17ffb54a9a23c5550a93a578b382f63d4ee2493 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sun, 7 May 2023 08:19:41 -0700 Subject: [PATCH 38/64] Changed pyproject.toml as @pushfoo sugested --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fcc43b075..477554991 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,7 +95,7 @@ select = [ [tool.mypy] -disable_error_code = "annotation-unchecked" +disable-error-code = union-attr [tool.pytest.ini_options] norecursedirs = ["doc", "holding", "arcade/examples", "build", ".venv", "env", "dist", "tempt"] From a2c6f5cb94fe819bf53ad0f8627d0699a016ac30 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sun, 7 May 2023 09:15:49 -0700 Subject: [PATCH 39/64] Revert pyproject change --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 477554991..fcc43b075 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,7 +95,7 @@ select = [ [tool.mypy] -disable-error-code = union-attr +disable_error_code = "annotation-unchecked" [tool.pytest.ini_options] norecursedirs = ["doc", "holding", "arcade/examples", "build", ".venv", "env", "dist", "tempt"] From f2ffcabc7607b96167b0b921600893af9a7bf665 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Wed, 10 May 2023 14:28:45 -0700 Subject: [PATCH 40/64] Add # type: ignore --- arcade/shape_list.py | 2 +- arcade/sprite_list/sprite_list.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arcade/shape_list.py b/arcade/shape_list.py index 3ad0df3b6..b86d517c5 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -118,7 +118,7 @@ def draw(self) -> None: if self.geometry is None: self._init_geometry() - self.geometry.render(self.program, mode=self.mode) + self.geometry.render(self.program, mode=self.mode)# type: ignore def create_line( diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index ee9819759..b5d5891da 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -1058,11 +1058,11 @@ def _grow_sprite_buffers(self) -> None: self._sprite_texture_data.extend([0] * extend_by) if self._initialized: - self._sprite_pos_buf.orphan(double=True) - self._sprite_size_buf.orphan(double=True) - self._sprite_angle_buf.orphan(double=True) - self._sprite_color_buf.orphan(double=True) - self._sprite_texture_buf.orphan(double=True) + self._sprite_pos_buf.orphan(double=True)# type: ignore + self._sprite_size_buf.orphan(double=True)# type: ignore + self._sprite_angle_buf.orphan(double=True)# type: ignore + self._sprite_color_buf.orphan(double=True)# type: ignore + self._sprite_texture_buf.orphan(double=True)# type: ignore self._sprite_pos_changed = True self._sprite_size_changed = True From b386371ec4763d4e7277addde3239a5b7eb0c6c8 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 12 May 2023 08:56:51 -0700 Subject: [PATCH 41/64] Small errors fixed --- arcade/application.py | 9 +++++---- arcade/draw_commands.py | 11 +++++------ arcade/easing.py | 17 +++++++++-------- arcade/gui/property.py | 7 ++----- arcade/math.py | 12 ++++++------ arcade/pymunk_physics_engine.py | 3 ++- arcade/shape_list.py | 2 +- arcade/sprite/sprite.py | 6 +++--- arcade/sprite_list/sprite_list.py | 5 +++-- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 003644621..0301cac70 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -231,7 +231,7 @@ def __init__( self.mouse = None @property - def current_view(self) -> Optional[View]: + def current_view(self) -> Optional["View"]: """ This property returns the current view being shown. To set a different view, call the @@ -707,7 +707,7 @@ def test(self, frames: int = 10) -> None: time.sleep(sleep_time) self._dispatch_updates(1 / 60) - def show_view(self, new_view: View) -> None: + def show_view(self, new_view: "View") -> None: """ Select the view to show in the next frame. This is not a blocking call showing the view. @@ -946,7 +946,7 @@ class View: """ Support different views/screens in a window. """ - + def __init__(self, window: Optional[Window] = None) -> None: @@ -969,7 +969,8 @@ def has_sections(self) -> bool: else: return self.section_manager.has_sections - def add_section(self, section: Section, at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: + def add_section(self, section: Section, at_index: Optional[int] = None, + at_draw_order: Optional[int] = None) -> None: """ Adds a section to the view Section Manager. diff --git a/arcade/draw_commands.py b/arcade/draw_commands.py index d7cacc459..201729130 100644 --- a/arcade/draw_commands.py +++ b/arcade/draw_commands.py @@ -405,7 +405,7 @@ def _generic_draw_line_strip(point_list: PointList, def draw_line_strip(point_list: PointList, - color: RGBA255, + color: RGBA255, line_width: float = 1) -> None: """ Draw a multi-point line. @@ -572,9 +572,8 @@ def draw_polygon_filled(point_list: PointList, flattened_list = tuple(i for g in triangle_points for i in g) _generic_draw_line_strip(flattened_list, color, gl.GL_TRIANGLES) - def draw_polygon_outline(point_list: PointList, - color: RGBA255, + color: RGBA255, line_width: float = 1) -> None: """ Draw a polygon outline. Also known as a "line loop." @@ -606,7 +605,7 @@ def draw_polygon_outline(point_list: PointList, def draw_triangle_filled(x1: float, y1: float, x2: float, y2: float, - x3: float, y3: float, + x3: float, y3: float, color: RGBA255) -> None: """ Draw a filled in triangle. @@ -951,11 +950,11 @@ def draw_texture_rectangle(center_x: float, center_y: float, texture.draw_sized(center_x, center_y, width, height, angle, alpha) -def draw_lrwh_rectangle_textured(bottom_left_x: float, +def draw_lrwh_rectangle_textured(bottom_left_x: float, bottom_left_y: float, width: float, height: float, - texture: Texture, + texture: Texture, angle: float = 0, alpha: int = 255) -> None: """ diff --git a/arcade/easing.py b/arcade/easing.py index e3f84813d..21e4be6c6 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -1,10 +1,11 @@ """ Functions used to support easing """ +from __future__ import annotations + from math import pi, sin, cos from dataclasses import dataclass -from typing import Callable, Tuple, Optional, Union -from __future__ import annotations +from typing import Callable, Tuple, Optional from .math import get_distance @@ -146,7 +147,7 @@ def easing(percent: float, easing_data: EasingData) -> float: easing_data.ease_function(percent) -def ease_angle(start_angle: float, end_angle: float, *, +def ease_angle(start_angle: float, end_angle: float, *, time=None, rate=None, ease_function: Callable = linear ) -> Optional[EasingData]: """ @@ -200,8 +201,8 @@ def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, return done, angle -def ease_value(start_value: float, end_value: float, *, time: - Optional[float]=None, rate: Optional[float]=None, +def ease_value(start_value: float, end_value: float, *, time: + Optional[float]=None, rate: Optional[float]=None, ease_function: Callable=linear) -> EasingData: """ Get an easing value @@ -223,9 +224,9 @@ def ease_value(start_value: float, end_value: float, *, time: return easing_data -def ease_position(start_position: Tuple[float, float], - end_position: Tuple[float, float], *, - time: Optional[float]=None, rate: +def ease_position(start_position: Tuple[float, float], + end_position: Tuple[float, float], *, + time: Optional[float]=None, rate: Optional[float]=None, ease_function: Callable=linear ) -> Tuple[EasingData, EasingData]: """ diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 2ff1f16ee..27095a588 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -2,7 +2,6 @@ import traceback from typing import ( Optional, - Union, Tuple, Callable, Any, @@ -10,8 +9,6 @@ Dict, List, Set, - Mapping, - overload, SupportsIndex ) from weakref import WeakKeyDictionary, ref @@ -197,12 +194,12 @@ def __delitem__(self, key: Any) -> None: list.__delitem__(self, key) self.dispatch() - def __iadd__(self, *largs: List) -> _ObservableList: # type: ignore + def __iadd__(self, *largs: List) -> "_ObservableList": # type: ignore list.__iadd__(self, *largs) self.dispatch() return self - def __imul__(self, *largs: int) -> _ObservableList: # type: ignore + def __imul__(self, *largs: int) -> "_ObservableList": # type: ignore list.__imul__(self, *largs) self.dispatch() return self diff --git a/arcade/math.py b/arcade/math.py index 7e4880d20..63805f220 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -231,20 +231,20 @@ def __init__(self, x: float, y: float) -> None: self.y: float = y @staticmethod - def from_polar(angle, radius: float) -> _Vec2: + def from_polar(angle, radius: float) -> "_Vec2": rads = math.radians(angle) return _Vec2(radius * math.cos(rads), radius * math.sin(rads)) - def __add__(self, other: _Vec2) -> _Vec2: + def __add__(self, other: "_Vec2") -> "_Vec2": return _Vec2(self.x + other.x, self.y + other.y) - def __sub__(self, other: _Vec2) -> _Vec2: + def __sub__(self, other: "_Vec2") -> "_Vec2": return _Vec2(self.x - other.x, self.y - other.y) - def __mul__(self, other: _Vec2) -> _Vec2: + def __mul__(self, other: "_Vec2") -> "_Vec2": return _Vec2(self.x * other.x, self.y * other.y) - def __truediv__(self, other: _Vec2) -> _Vec2: + def __truediv__(self, other: "_Vec2") -> "_Vec2": return _Vec2(self.x / other.x, self.y / other.y) def __iter__(self): @@ -255,7 +255,7 @@ def length(self) -> float: """return the length (magnitude) of the vector""" return math.sqrt(self.x**2 + self.y**2) - def dot(self, other: _Vec2) -> float: + def dot(self, other: "_Vec2") -> float: return self.x * other.x + self.y * other.y def __repr__(self): diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index acb13e6d8..134f6c0e3 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -50,7 +50,8 @@ class PymunkPhysicsEngine: KINEMATIC = pymunk.Body.KINEMATIC MOMENT_INF = float('inf') - def __init__(self, gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]]=(0, 0), damping: float = 1.0, maximum_incline_on_ground: float = 0.708): + def __init__(self, gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]]=(0, 0), + damping: float = 1.0, maximum_incline_on_ground: float = 0.708): # -- Pymunk self.space = pymunk.Space() self.space.gravity = gravity diff --git a/arcade/shape_list.py b/arcade/shape_list.py index b86d517c5..97a385064 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -25,7 +25,7 @@ import pyglet.gl as gl -from arcade.types import Color, Point, PointList, RGBA255, BufferProtocol +from arcade.types import Color, Point, PointList, RGBA255 from arcade import get_window, get_points_for_thick_line from arcade.gl import BufferDescription, Program, Geometry, Buffer from arcade import ArcadeContext diff --git a/arcade/sprite/sprite.py b/arcade/sprite/sprite.py index 609dbbf02..a1488d124 100644 --- a/arcade/sprite/sprite.py +++ b/arcade/sprite/sprite.py @@ -1,6 +1,8 @@ +from __future__ import annotations + import math from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, Callable +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from arcade import Texture, load_texture from arcade.hitbox import HitBox, RotatableHitBox @@ -8,8 +10,6 @@ from arcade.texture import get_default_texture from arcade.types import PathOrTexture, Point -from __future__ import annotations - from .base import BasicSprite from .mixins import PymunkMixin diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index b5d5891da..a3ad304c6 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -965,8 +965,9 @@ def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, blend_funct `gl.GL_NEAREST` to avoid smoothing. :param bool pixelated: ``True`` for pixelated and ``False`` for smooth interpolation. Shortcut for setting filter=GL_NEAREST. - :param Optional[gl blend function] blend_function: Optional parameter to set the OpenGL blend function used for drawing the - sprite list, such as 'arcade.Window.ctx.BLEND_ADDITIVE' or 'arcade.Window.ctx.BLEND_DEFAULT' + :param Optional[gl blend function] blend_function: Optional parameter to set the OpenGL blend + function used for drawing the sprite list, such as + 'arcade.Window.ctx.BLEND_ADDITIVE' or 'arcade.Window.ctx.BLEND_DEFAULT' """ if len(self.sprite_list) == 0 or not self._visible or self.alpha_normalized == 0.0: return From 9ba0c55c901f5701a9226b164f6042819ec8e383 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Wed, 17 May 2023 17:24:39 -0700 Subject: [PATCH 42/64] . --- arcade/application.py | 2 +- arcade/pymunk_physics_engine.py | 2 +- arcade/sprite_list/sprite_list.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 0301cac70..f12ba7f0a 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -969,7 +969,7 @@ def has_sections(self) -> bool: else: return self.section_manager.has_sections - def add_section(self, section: Section, at_index: Optional[int] = None, + def add_section(self, section: Section, at_index: Optional[int] = None, at_draw_order: Optional[int] = None) -> None: """ Adds a section to the view Section Manager. diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index 134f6c0e3..2e208031a 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -50,7 +50,7 @@ class PymunkPhysicsEngine: KINEMATIC = pymunk.Body.KINEMATIC MOMENT_INF = float('inf') - def __init__(self, gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]]=(0, 0), + def __init__(self, gravity: Optional[Union[pymunk.Vec2d, Tuple[float, float], Vec2]]=(0, 0), damping: float = 1.0, maximum_incline_on_ground: float = 0.708): # -- Pymunk self.space = pymunk.Space() diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index a3ad304c6..428dcf1dc 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -964,9 +964,9 @@ def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, blend_funct :param Optional[gl filter] filter: Optional parameter to set OpenGL filter, such as `gl.GL_NEAREST` to avoid smoothing. :param bool pixelated: ``True`` for pixelated and ``False`` for smooth interpolation. - Shortcut for setting filter=GL_NEAREST. - :param Optional[gl blend function] blend_function: Optional parameter to set the OpenGL blend - function used for drawing the sprite list, such as + Shortcut for setting filter=GL_NEAREST + :param Optional[gl blend function] blend_function: Optional parameter to set the OpenGL blend + function used for drawing the sprite list, such as 'arcade.Window.ctx.BLEND_ADDITIVE' or 'arcade.Window.ctx.BLEND_DEFAULT' """ if len(self.sprite_list) == 0 or not self._visible or self.alpha_normalized == 0.0: From 16cccf69ba1b5e917ff5ab5b2b2d3489840a8907 Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Fri, 26 May 2023 13:10:45 -0700 Subject: [PATCH 43/64] Update arcade/application.py Co-authored-by: Paul <36696816+pushfoo@users.noreply.github.com> --- arcade/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/application.py b/arcade/application.py index dc1eb73d1..cab97b261 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -44,7 +44,7 @@ ] -def get_screens() -> list: +def get_screens() -> List[Screen]: """ Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which From 5a8e8fb416a2419d1f4c4a04c6b0b33351f5af0e Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Fri, 26 May 2023 13:11:00 -0700 Subject: [PATCH 44/64] Update arcade/gui/property.py Co-authored-by: Paul <36696816+pushfoo@users.noreply.github.com> --- arcade/gui/property.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 46d038f07..16103be6e 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -12,6 +12,7 @@ Dict, List, Set, + SupportsIndex, cast ) from weakref import WeakKeyDictionary, ref From 60b6f3d7c448ff2d19220e32a554e8c6570b49e0 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 13:15:08 -0700 Subject: [PATCH 45/64] cspotcode's fixes --- arcade/perf_info.py | 3 ++- arcade/sprite_list/sprite_list.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arcade/perf_info.py b/arcade/perf_info.py index cf790993b..4e534cd6e 100644 --- a/arcade/perf_info.py +++ b/arcade/perf_info.py @@ -87,7 +87,8 @@ def print_timings() -> None: on_draw 60 0.0020 """ global _timings - print("\nEvent Count Average Time") + print() + print("Event Count Average Time") print("-------------- ----- ------------") for index in _timings: data = _timings[index] diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 2df9db83a..aff78dbe9 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -957,7 +957,7 @@ def initialize(self): """ self._init_deferred() - def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, blend_function: Optional[int]=None) -> None: + def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, blend_function: Union[Tuple[int, int], Tuple[int, int, int, int], None]=None) -> None: """ Draw this list of sprites. @@ -1059,11 +1059,11 @@ def _grow_sprite_buffers(self) -> None: self._sprite_texture_data.extend([0] * extend_by) if self._initialized: - self._sprite_pos_buf.orphan(double=True)# type: ignore - self._sprite_size_buf.orphan(double=True)# type: ignore - self._sprite_angle_buf.orphan(double=True)# type: ignore - self._sprite_color_buf.orphan(double=True)# type: ignore - self._sprite_texture_buf.orphan(double=True)# type: ignore + self._sprite_pos_buf.orphan(double=True) + self._sprite_size_buf.orphan(double=True) + self._sprite_angle_buf.orphan(double=True) + self._sprite_color_buf.orphan(double=True) + self._sprite_texture_buf.orphan(double=True) self._sprite_pos_changed = True self._sprite_size_changed = True From 003445080cf3d16da674b7428d697282e059ac11 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 13:19:06 -0700 Subject: [PATCH 46/64] // --- arcade/math.py | 11 ++++++----- arcade/sprite_list/sprite_list.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arcade/math.py b/arcade/math.py index 63805f220..f797fd4a1 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -1,6 +1,7 @@ import math import random from arcade.types import Point, Vector +from typing_extensions import Self _PRECISION = 2 @@ -231,20 +232,20 @@ def __init__(self, x: float, y: float) -> None: self.y: float = y @staticmethod - def from_polar(angle, radius: float) -> "_Vec2": + def from_polar(angle, radius: float) -> Self: rads = math.radians(angle) return _Vec2(radius * math.cos(rads), radius * math.sin(rads)) - def __add__(self, other: "_Vec2") -> "_Vec2": + def __add__(self, other: "_Vec2") -> Self: return _Vec2(self.x + other.x, self.y + other.y) - def __sub__(self, other: "_Vec2") -> "_Vec2": + def __sub__(self, other: "_Vec2") -> Self: return _Vec2(self.x - other.x, self.y - other.y) - def __mul__(self, other: "_Vec2") -> "_Vec2": + def __mul__(self, other: "_Vec2") -> Self: return _Vec2(self.x * other.x, self.y * other.y) - def __truediv__(self, other: "_Vec2") -> "_Vec2": + def __truediv__(self, other: "_Vec2") -> Self: return _Vec2(self.x / other.x, self.y / other.y) def __iter__(self): diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index aff78dbe9..67b981aa0 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -368,7 +368,7 @@ def alpha_normalized(self, value: float): self._color = self._color[0], self._color[1], self._color[2], value @property - def atlas(self) -> "TextureAtlas": + def atlas(self) -> TextureAtlas: """Get the texture atlas for this sprite list""" return self._atlas From 1c0af3cc3bf4a27996ab0ec3814a0ae812597687 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 13:19:55 -0700 Subject: [PATCH 47/64] lol --- arcade/gl/vertex_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/gl/vertex_array.py b/arcade/gl/vertex_array.py index d9b119bb0..b973fe71d 100644 --- a/arcade/gl/vertex_array.py +++ b/arcade/gl/vertex_array.py @@ -240,7 +240,7 @@ def _build( def render( self, mode: GLenumLike, first: int = 0, vertices: int = 0, instances: int = 1 - + ) -> None: """Render the VertexArray to the currently active framebuffer. :param GLuint mode: Primitive type to render. TRIANGLES, LINES etc. From 93761b6ea18dec30e15f7bebd7f7a517ccee2fd5 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 16:05:20 -0700 Subject: [PATCH 48/64] added future immport annotations --- arcade/math.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arcade/math.py b/arcade/math.py index f797fd4a1..17862d164 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import math import random from arcade.types import Point, Vector From 5fe6a2395c803df20c7911de73184f505a2647c8 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sat, 27 May 2023 14:53:01 -0700 Subject: [PATCH 49/64] Remove generics --- arcade/gui/property.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 16103be6e..3d7d34301 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -50,7 +50,7 @@ def __init__(self, default: Optional[P] = None, default_factory: Optional[Callab self.default_factory = default_factory self.obs: WeakKeyDictionary[Any, _Obs] = WeakKeyDictionary() - def _get_obs(self, instance: Any) -> _Obs: + def _get_obs(self, instance) -> _Obs: obs = self.obs.get(instance) if obs is None: obs = _Obs(self.default_factory(self, instance)) @@ -61,13 +61,13 @@ def get(self, instance) -> P: obs = self._get_obs(instance) return obs.value - def set(self, instance: Any, value: Any) -> None: + def set(self, instance, value) -> None: obs = self._get_obs(instance) if obs.value != value: obs.value = value self.dispatch(instance, value) - def dispatch(self, instance: Any, value: Any) -> None: + def dispatch(self, instance, value) -> None: obs = self._get_obs(instance) for listener in obs.listeners: try: @@ -79,7 +79,7 @@ def dispatch(self, instance: Any, value: Any) -> None: ) traceback.print_exc() - def bind(self, instance: Any, callback: Callable) -> None: + def bind(self, instance, callback: Callable) -> None: obs = self._get_obs(instance) # Instance methods are bound methods, which can not be referenced by normal `ref()` # if listeners would be a WeakSet, we would have to add listeners as WeakMethod ourselves into `WeakSet.data`. @@ -93,7 +93,7 @@ def __get__(self, instance, owner) -> P: return self # type: ignore return self.get(instance) - def __set__(self, instance: Any, value: Any) -> None: + def __set__(self, instance, value) -> None: self.set(instance, value) @@ -147,7 +147,7 @@ def clear(self) -> None: dict.clear(self) self.dispatch() - def pop(self, *largs: Any) -> Any: + def pop(self, *largs): result = dict.pop(self, *largs) self.dispatch() return result @@ -157,7 +157,7 @@ def popitem(self) -> Tuple[Any, Any]: self.dispatch() return result - def setdefault(self, *largs: Any) -> None: + def setdefault(self, *largs) -> None: dict.setdefault(self, *largs) self.dispatch() @@ -175,14 +175,14 @@ class DictProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableDict) - def set(self, instance: Any, value: Dict) -> None: + def set(self, instance, value: Dict) -> None: value = _ObservableDict(self, instance, value) super().set(instance, value) class _ObservableList(list): # Internal class to observe changes inside a native python list. - def __init__(self, prop: Property, instance: Any, *largs: List) -> None: + def __init__(self, prop: Property, instance, *largs: List) -> None: self.prop: Property = prop self.obj = ref(instance) super().__init__(*largs) @@ -190,11 +190,11 @@ def __init__(self, prop: Property, instance: Any, *largs: List) -> None: def dispatch(self) -> None: self.prop.dispatch(self.obj(), self) - def __setitem__(self, key, value: Any) -> None: + def __setitem__(self, key, value) -> None: list.__setitem__(self, key, value) self.dispatch() - def __delitem__(self, key: Any) -> None: + def __delitem__(self, key) -> None: list.__delitem__(self, key) self.dispatch() @@ -208,7 +208,7 @@ def __imul__(self, *largs: int) -> "_ObservableList": # type: ignore self.dispatch() return self - def append(self, *largs: Any) -> None: + def append(self, *largs) -> None: list.append(self, *largs) self.dispatch() @@ -216,15 +216,15 @@ def clear(self) -> None: list.clear(self) self.dispatch() - def remove(self, *largs: Any) -> None: + def remove(self, *largs) -> None: list.remove(self, *largs) self.dispatch() - def insert(self, *largs: Any) -> None: + def insert(self, *largs) -> None: list.insert(self, *largs) self.dispatch() - def pop(self, *largs: SupportsIndex) -> Any: + def pop(self, *largs: SupportsIndex) : result = list.pop(self, *largs) self.dispatch() return result @@ -251,6 +251,6 @@ class ListProperty(Property): def __init__(self) -> None: super().__init__(default_factory=_ObservableList) - def set(self, instance: Any, value: List) -> None: + def set(self, instance, value: List) -> None: value = _ObservableList(self, instance, value) # type: ignore super().set(instance, value) From 7f6de7059411e9a2f4f0d282f76c4912a7c5781b Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sat, 3 Jun 2023 14:28:45 -0700 Subject: [PATCH 50/64] Requested fixes --- arcade/gui/property.py | 4 ++-- arcade/math.py | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 3d7d34301..8ca026b38 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -198,7 +198,7 @@ def __delitem__(self, key) -> None: list.__delitem__(self, key) self.dispatch() - def __iadd__(self, *largs: List) -> "_ObservableList": # type: ignore + def __iadd__(self, *largs: Iterable) -> "_ObservableList": # type: ignore list.__iadd__(self, *largs) self.dispatch() return self @@ -229,7 +229,7 @@ def pop(self, *largs: SupportsIndex) : self.dispatch() return result - def extend(self, *largs: Iterable[Any]) -> None: + def extend(self, *largs: Iterable) -> None: list.extend(self, *largs) self.dispatch() diff --git a/arcade/math.py b/arcade/math.py index 17862d164..b2b42fdb2 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -3,7 +3,6 @@ import math import random from arcade.types import Point, Vector -from typing_extensions import Self _PRECISION = 2 @@ -234,20 +233,20 @@ def __init__(self, x: float, y: float) -> None: self.y: float = y @staticmethod - def from_polar(angle, radius: float) -> Self: + def from_polar(angle, radius: float) -> _Vec2: rads = math.radians(angle) return _Vec2(radius * math.cos(rads), radius * math.sin(rads)) - def __add__(self, other: "_Vec2") -> Self: + def __add__(self, other: "_Vec2") -> _Vec2: return _Vec2(self.x + other.x, self.y + other.y) - def __sub__(self, other: "_Vec2") -> Self: + def __sub__(self, other: "_Vec2") -> _Vec2: return _Vec2(self.x - other.x, self.y - other.y) - def __mul__(self, other: "_Vec2") -> Self: + def __mul__(self, other: "_Vec2") -> _Vec2: return _Vec2(self.x * other.x, self.y * other.y) - def __truediv__(self, other: "_Vec2") -> Self: + def __truediv__(self, other: "_Vec2") -> _Vec2: return _Vec2(self.x / other.x, self.y / other.y) def __iter__(self): From a3e51d47782ebbe3763fa0ab9f437a97be18a6e0 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sat, 3 Jun 2023 14:28:58 -0700 Subject: [PATCH 51/64] correct import in application --- arcade/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/application.py b/arcade/application.py index cab97b261..55fa3895f 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -11,7 +11,7 @@ import pyglet.gl as gl import pyglet.window.mouse -from pyglet.canvas.base import ScreenMode +from pyglet.canvas.base import ScreenMode, Screen from pyglet.window import MouseCursor import arcade From a5a6fc78dd774485153ce87f726c8003d0c45537 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sat, 3 Jun 2023 14:31:15 -0700 Subject: [PATCH 52/64] Add # type: ignore to speed it up --- arcade/shape_list.py | 2 +- arcade/sprite_list/sprite_list.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arcade/shape_list.py b/arcade/shape_list.py index e4957d459..efa4dd64b 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -118,7 +118,7 @@ def draw(self) -> None: if self.geometry is None: self._init_geometry() - self.geometry.render(self.program, mode=self.mode) # pyright: ignore [reportOptionalMemberAccess] + self.geometry.render(self.program, mode=self.mode) # type: ignore def create_line( start_x: float, diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 67b981aa0..a6abe8ca0 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -1059,11 +1059,11 @@ def _grow_sprite_buffers(self) -> None: self._sprite_texture_data.extend([0] * extend_by) if self._initialized: - self._sprite_pos_buf.orphan(double=True) - self._sprite_size_buf.orphan(double=True) - self._sprite_angle_buf.orphan(double=True) - self._sprite_color_buf.orphan(double=True) - self._sprite_texture_buf.orphan(double=True) + self._sprite_pos_buf.orphan(double=True) # type: ignore + self._sprite_size_buf.orphan(double=True) # type: ignore + self._sprite_angle_buf.orphan(double=True) # type: ignore + self._sprite_color_buf.orphan(double=True) # type: ignore + self._sprite_texture_buf.orphan(double=True) # type: ignore self._sprite_pos_changed = True self._sprite_size_changed = True From 58805a76a6e6b0c0dd7363489deb646603f90a93 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sun, 4 Jun 2023 02:43:51 -0700 Subject: [PATCH 53/64] Line was too long --- arcade/sprite_list/sprite_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index a6abe8ca0..3f1f73de1 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -957,7 +957,8 @@ def initialize(self): """ self._init_deferred() - def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, blend_function: Union[Tuple[int, int], Tuple[int, int, int, int], None]=None) -> None: + def draw(self, *, filter: Optional[int]=None, pixelated: bool=False, + blend_function: Union[Tuple[int, int], Tuple[int, int, int, int], None]=None) -> None: """ Draw this list of sprites. From 3e867fa6c5e5e99e10f51771b01cb1fcf5066f84 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Mon, 12 Jun 2023 23:36:07 -0700 Subject: [PATCH 54/64] Fixes --- arcade/gl/vertex_array.py | 6 ++---- arcade/sprite_list/sprite_list.py | 9 +++------ arcade/utils.py | 4 ++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/arcade/gl/vertex_array.py b/arcade/gl/vertex_array.py index b973fe71d..df9fb5d60 100644 --- a/arcade/gl/vertex_array.py +++ b/arcade/gl/vertex_array.py @@ -1,5 +1,5 @@ from ctypes import c_void_p, byref -from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union +from typing import Dict, List, Optional, Sequence, Union import weakref from pyglet import gl @@ -8,8 +8,6 @@ from .types import BufferDescription, GLenumLike, GLuintLike, gl_name from .program import Program -if TYPE_CHECKING: # handle import cycle caused by type hinting - from arcade.gl import Context index_types = [None, gl.GL_UNSIGNED_BYTE, gl.GL_UNSIGNED_SHORT, None, gl.GL_UNSIGNED_INT] @@ -69,7 +67,7 @@ def __del__(self) -> None: self._ctx.objects.append(self) @property - def ctx(self) -> Context: + def ctx(self) -> "Context": """ The Context this object belongs to diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 3f1f73de1..c746383ee 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -34,9 +34,6 @@ from arcade.gl.buffer import Buffer from arcade.gl.vertex_array import Geometry -if TYPE_CHECKING: - from arcade import Texture, TextureAtlas - LOG = logging.getLogger(__name__) # The slot index that makes a sprite invisible. @@ -102,7 +99,7 @@ def __init__( ): self.program = None if atlas: - self._atlas: TextureAtlas = atlas + self._atlas = atlas self._initialized = False self._lazy = lazy self._visible = visible @@ -186,7 +183,7 @@ def _init_deferred(self): self.ctx = get_window().ctx self.program = self.ctx.sprite_list_program_cull - self._atlas: TextureAtlas = ( + self._atlas = ( getattr(self, "_atlas", None) or self.ctx.default_atlas ) @@ -368,7 +365,7 @@ def alpha_normalized(self, value: float): self._color = self._color[0], self._color[1], self._color[2], value @property - def atlas(self) -> TextureAtlas: + def atlas(self) -> "TextureAtlas": """Get the texture atlas for this sprite list""" return self._atlas diff --git a/arcade/utils.py b/arcade/utils.py index a989eccb8..096e88727 100644 --- a/arcade/utils.py +++ b/arcade/utils.py @@ -7,7 +7,7 @@ import functools import platform import sys -import warnings +from warnings import warn from typing import Tuple, Type, TypeVar from pathlib import Path @@ -126,7 +126,7 @@ def actual_warning_decorator(func): message = f"{func.__name__} is deprecated. Use {kwargs.get('new_name', '')} instead." @functools.wraps(func) def wrapper(*args, **kwargs): - warnings.warn(message, warning_type) + warn(message, warning_type) return func(*args, **kwargs) return wrapper return actual_warning_decorator From 29e863220caad5fd3a1952e4e6327bbd1306af7a Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Fri, 16 Jun 2023 19:09:12 -0700 Subject: [PATCH 55/64] .. --- arcade/gl/vertex_array.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arcade/gl/vertex_array.py b/arcade/gl/vertex_array.py index df9fb5d60..32d321425 100644 --- a/arcade/gl/vertex_array.py +++ b/arcade/gl/vertex_array.py @@ -1,5 +1,5 @@ from ctypes import c_void_p, byref -from typing import Dict, List, Optional, Sequence, Union +from typing import Dict, List, Optional, Sequence, Union, TYPE_CHECKING import weakref from pyglet import gl @@ -8,6 +8,9 @@ from .types import BufferDescription, GLenumLike, GLuintLike, gl_name from .program import Program +if TYPE_CHECKING: + from .context import Context + index_types = [None, gl.GL_UNSIGNED_BYTE, gl.GL_UNSIGNED_SHORT, None, gl.GL_UNSIGNED_INT] From 6a0a779385b404dc2099a879845ed4126554e461 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Fri, 16 Jun 2023 19:14:56 -0700 Subject: [PATCH 56/64] ... --- arcade/sprite_list/sprite_list.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 00887a8c0..95ac21da7 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -35,6 +35,10 @@ from arcade.gl.buffer import Buffer from arcade.gl.vertex_array import Geometry +if TYPE_CHECKING: + from arcade import TextureAtlas, Texture + + LOG = logging.getLogger(__name__) # The slot index that makes a sprite invisible. From 135f7caa1cb0e21cb8ebcfe283f1b78ee57e5488 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sat, 17 Jun 2023 18:05:56 -0700 Subject: [PATCH 57/64] .. --- arcade/application.py | 2 +- arcade/pymunk_physics_engine.py | 2 +- arcade/sprite/sprite.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 55fa3895f..f82460e11 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -44,7 +44,7 @@ ] -def get_screens() -> List[Screen]: +def get_screens(): """ Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index 2e208031a..dfccffd31 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -135,7 +135,7 @@ def add_sprite(self, body.angle = math.radians(sprite.angle) # Callback used if we need custom gravity, damping, velocity, etc. - def velocity_callback(my_body: pymunk.Body, my_gravity: Tuple[float, float], my_damping: float, dt: float): + def velocity_callback(my_body: pymunk.Body, my_gravity: Union[pymunk.Vec2d, Tuple[float, float], Vec2], my_damping: float, dt: float): """ Used for custom damping, gravity, and max_velocity. """ # Custom damping diff --git a/arcade/sprite/sprite.py b/arcade/sprite/sprite.py index 3aabd093e..11276afa1 100644 --- a/arcade/sprite/sprite.py +++ b/arcade/sprite/sprite.py @@ -315,7 +315,7 @@ def stop(self) -> None: # ---- Draw Methods ---- - def draw(self, *, filter=None, pixelated=None, blend_function=None) -> None: + def draw(self, *, filter=None, pixelated=False, blend_function=None) -> None: """ A debug method which draws the sprite into the current OpenGL context. From 4b344bfedee811d2d886a9516c8390961f3b4c86 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Sat, 17 Jun 2023 18:08:48 -0700 Subject: [PATCH 58/64] . --- arcade/application.py | 2 +- arcade/pymunk_physics_engine.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index f82460e11..344f165f3 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -11,7 +11,7 @@ import pyglet.gl as gl import pyglet.window.mouse -from pyglet.canvas.base import ScreenMode, Screen +from pyglet.canvas.base import ScreenMode from pyglet.window import MouseCursor import arcade diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index dfccffd31..02edd0481 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -135,7 +135,8 @@ def add_sprite(self, body.angle = math.radians(sprite.angle) # Callback used if we need custom gravity, damping, velocity, etc. - def velocity_callback(my_body: pymunk.Body, my_gravity: Union[pymunk.Vec2d, Tuple[float, float], Vec2], my_damping: float, dt: float): + def velocity_callback(my_body: pymunk.Body, my_gravity: Union[pymunk.Vec2d, Tuple[float, float], Vec2], + my_damping: float, dt: float) -> None: """ Used for custom damping, gravity, and max_velocity. """ # Custom damping From aeb3819f5aa4c5bdbcc80b4d37943be1fbf38e0e Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Thu, 22 Jun 2023 15:42:36 -0700 Subject: [PATCH 59/64] . --- arcade/pymunk_physics_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index 02edd0481..eb07a6417 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -135,7 +135,7 @@ def add_sprite(self, body.angle = math.radians(sprite.angle) # Callback used if we need custom gravity, damping, velocity, etc. - def velocity_callback(my_body: pymunk.Body, my_gravity: Union[pymunk.Vec2d, Tuple[float, float], Vec2], + def velocity_callback(my_body: pymunk.Body, my_gravity: Tuple[float, float], my_damping: float, dt: float) -> None: """ Used for custom damping, gravity, and max_velocity. """ From 929d87fed267326389f498f0cd9a243d82842f77 Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Thu, 22 Jun 2023 15:51:36 -0700 Subject: [PATCH 60/64] . --- arcade/pymunk_physics_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index eb07a6417..6bf8ee779 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -135,7 +135,7 @@ def add_sprite(self, body.angle = math.radians(sprite.angle) # Callback used if we need custom gravity, damping, velocity, etc. - def velocity_callback(my_body: pymunk.Body, my_gravity: Tuple[float, float], + def velocity_callback(my_body: pymunk.Body, my_gravity: Tuple[float, float], # pyright: ignore my_damping: float, dt: float) -> None: """ Used for custom damping, gravity, and max_velocity. """ From eb1f7d77a57e324b01945e95873946fcfb7d4163 Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Wed, 28 Jun 2023 09:19:28 +0900 Subject: [PATCH 61/64] . --- arcade/easing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/easing.py b/arcade/easing.py index 21e4be6c6..3640095f6 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -202,7 +202,7 @@ def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, def ease_value(start_value: float, end_value: float, *, time: - Optional[float]=None, rate: Optional[float]=None, + float=0, rate: float=0, ease_function: Callable=linear) -> EasingData: """ Get an easing value From 53237fab05ed6b6898aec51f036890f7ffa983a5 Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Wed, 5 Jul 2023 13:11:48 -0700 Subject: [PATCH 62/64] . --- arcade/easing.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arcade/easing.py b/arcade/easing.py index 3640095f6..f916b9146 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -240,8 +240,14 @@ def ease_position(start_position: Tuple[float, float], if rate is not None: time = distance / rate - easing_data_x: EasingData = ease_value(start_position[0], end_position[0], time=time, ease_function=ease_function) - easing_data_y: EasingData = ease_value(start_position[1], end_position[1], time=time, ease_function=ease_function) + easing_data_x: EasingData = ease_value( + start_position[0], end_position[0], + time=time, ease_function=ease_function # type: ignore[arg-type] + ) + easing_data_y: EasingData = ease_value( + start_position[1], end_position[1], + time=time, ease_function=ease_function # type: ignore[arg-type] + ) return easing_data_x, easing_data_y From 21f3a8bc07b2f72b21feb33219861a7ca0fe84ef Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Wed, 5 Jul 2023 13:56:33 -0700 Subject: [PATCH 63/64] . --- arcade/pymunk_physics_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index 6bf8ee779..d27599f96 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -147,7 +147,7 @@ def velocity_callback(my_body: pymunk.Body, my_gravity: Tuple[float, float], # # Custom gravity if sprite.pymunk.gravity is not None: - my_gravity = sprite.pymunk.gravity + my_gravity = sprite.pymunk.gravity # type: ignore # Go ahead and update velocity pymunk.Body.update_velocity(my_body, my_gravity, my_damping, dt) From bc472c2e21ee0693ab32867a640270583e8694b9 Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Tue, 26 Sep 2023 18:20:05 -0700 Subject: [PATCH 64/64] Update draw_commands.py --- arcade/draw_commands.py | 51 +++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/arcade/draw_commands.py b/arcade/draw_commands.py index 201729130..4eb3e3f11 100644 --- a/arcade/draw_commands.py +++ b/arcade/draw_commands.py @@ -216,8 +216,7 @@ def draw_parabola_outline(start_x: float, start_y: float, end_x: float, # --- BEGIN CIRCLE FUNCTIONS # # # def draw_circle_filled(center_x: float, center_y: float, radius: float, - color: RGBA255, - tilt_angle: float = 0, + color: RGBA255, tilt_angle: float = 0, num_segments: int = -1) -> None: """ Draw a filled-in circle. @@ -240,8 +239,7 @@ def draw_circle_filled(center_x: float, center_y: float, radius: float, def draw_circle_outline(center_x: float, center_y: float, radius: float, color: RGBA255, border_width: float = 1, - tilt_angle: float = 0, - num_segments: int = -1) -> None: + tilt_angle: float = 0, num_segments: int = -1) -> None: """ Draw the outline of a circle. @@ -315,10 +313,8 @@ def draw_ellipse_filled(center_x: float, center_y: float, def draw_ellipse_outline(center_x: float, center_y: float, - width: float, - height: float, color: RGBA255, - border_width: float = 1, - tilt_angle: float = 0, + width: float, height: float, color: RGBA255, + border_width: float = 1, tilt_angle: float = 0, num_segments: int = -1) -> None: """ Draw the outline of an ellipse. @@ -366,8 +362,7 @@ def draw_ellipse_outline(center_x: float, center_y: float, # --- BEGIN LINE FUNCTIONS # # # -def _generic_draw_line_strip(point_list: PointList, - color: RGBA255, +def _generic_draw_line_strip(point_list: PointList, color: RGBA255, mode: int = gl.GL_LINE_STRIP) -> None: """ Draw a line strip. A line strip is a set of continuously connected @@ -404,8 +399,7 @@ def _generic_draw_line_strip(point_list: PointList, geometry.render(program, mode=mode) -def draw_line_strip(point_list: PointList, - color: RGBA255, +def draw_line_strip(point_list: PointList, color: RGBA255, line_width: float = 1) -> None: """ Draw a multi-point line. @@ -464,8 +458,7 @@ def draw_line(start_x: float, start_y: float, end_x: float, end_y: float, geometry.render(program, mode=gl.GL_LINES, vertices=2) -def draw_lines(point_list: PointList, - color: RGBA255, +def draw_lines(point_list: PointList, color: RGBA255, line_width: float = 1) -> None: """ Draw a set of lines. @@ -559,8 +552,7 @@ def draw_points(point_list: PointList, color: RGBA255, size: float = 1) -> None: # --- BEGIN POLYGON FUNCTIONS # # # -def draw_polygon_filled(point_list: PointList, - color: RGBA255) -> None: +def draw_polygon_filled(point_list: PointList, color: RGBA255) -> None: """ Draw a polygon that is filled in. @@ -572,8 +564,7 @@ def draw_polygon_filled(point_list: PointList, flattened_list = tuple(i for g in triangle_points for i in g) _generic_draw_line_strip(flattened_list, color, gl.GL_TRIANGLES) -def draw_polygon_outline(point_list: PointList, - color: RGBA255, +def draw_polygon_outline(point_list: PointList, color: RGBA255, line_width: float = 1) -> None: """ Draw a polygon outline. Also known as a "line loop." @@ -588,18 +579,18 @@ def draw_polygon_outline(point_list: PointList, new_point_list.append(point_list[0]) triangle_point_list = [] - # This needs a lot of improvement - last_point = None - for point in new_point_list: - if last_point is not None: - points = get_points_for_thick_line(last_point[0], last_point[1], point[0], point[1], line_width) - reordered_points = points[1], points[0], points[2], points[3] - triangle_point_list.extend(reordered_points) - last_point = point - - points = get_points_for_thick_line(new_point_list[0][0], new_point_list[0][1], new_point_list[1][0], - new_point_list[1][1], line_width) - triangle_point_list.append(points[1]) + for i in range(len(point_list) - 1): + point1 = point_list[i] + point2 = point_list[i + 1] + + points = get_points_for_thick_line(point1[0], point1[1], point2[0], point2[1], line_width) + triangle_point_list.extend([points[1], points[0], points[2], points[3]]) + + # Handle the last segment (connecting back to the start) + point1 = point_list[-1] + point2 = point_list[0] + points = get_points_for_thick_line(point1[0], point1[1], point2[0], point2[1], line_width) + triangle_point_list.extend([points[1], points[0], points[2], points[3]]) _generic_draw_line_strip(triangle_point_list, color, gl.GL_TRIANGLE_STRIP)