From 376e8028a1f39524e504349c56cb0ee629f105ca Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Fri, 28 Mar 2025 16:04:52 +0100 Subject: [PATCH 1/5] =?UTF-8?q?drop=20Python=203.9=20=F0=9F=A5=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/selfhosted_runner.yml | 2 +- CHANGELOG.md | 7 +- arcade/__init__.py | 2 - arcade/__main__.py | 2 - arcade/__pyinstaller/__init__.py | 2 - arcade/__pyinstaller/hook-arcade.py | 2 - arcade/cache/__init__.py | 2 - arcade/cache/texture.py | 2 - arcade/camera/data_types.py | 2 - arcade/camera/grips/position.py | 2 - arcade/camera/grips/rotate.py | 2 - arcade/camera/grips/screen_shake_2d.py | 2 - arcade/camera/grips/strafe.py | 2 - arcade/camera/projection_functions.py | 2 - arcade/clock.py | 2 - arcade/color/__init__.py | 2 - arcade/context.py | 2 - arcade/controller.py | 2 - arcade/csscolor/__init__.py | 2 - arcade/draw/rect.py | 2 - arcade/earclip.py | 2 - arcade/easing.py | 2 - arcade/examples/depth_of_field.py | 2 - arcade/examples/gui/2_widgets.py | 2 - arcade/examples/gui/3_buttons.py | 2 - arcade/examples/gui/4_with_camera.py | 2 - arcade/examples/gui/6_size_hints.py | 2 - arcade/examples/gui/exp_hidden_password.py | 2 - arcade/examples/gui/exp_restricted_input.py | 2 - arcade/examples/gui/exp_scroll_area.py | 3 - arcade/examples/gui/ninepatch.py | 2 - arcade/examples/gui/own_layout.py | 2 - arcade/examples/gui/own_widget.py | 2 - arcade/examples/particle_fireworks.py | 1 - arcade/examples/performance_statistics.py | 1 - arcade/examples/pymunk_demo_top_down.py | 1 - arcade/examples/sections_demo_1.py | 2 - arcade/examples/sections_demo_3.py | 2 - arcade/examples/sprite_depth_cosine.py | 2 - arcade/examples/threaded_loading.py | 2 - arcade/experimental/__init__.py | 2 - arcade/experimental/atlas_load_save.py | 112 ----------- arcade/experimental/atlas_render_into.py | 2 - arcade/experimental/atlas_replace_image.py | 2 - arcade/experimental/bloom_filter.py | 2 - arcade/experimental/crt_filter.py | 2 - arcade/experimental/gaussian_kernel.py | 2 - arcade/experimental/geo_culling_check.py | 2 - arcade/experimental/postprocessing.py | 2 - arcade/experimental/profiling.py | 2 - arcade/experimental/pygame_interaction.py | 2 - arcade/experimental/query_demo.py | 2 - .../experimental/render_offscreen_animated.py | 2 - arcade/experimental/shadertoy.py | 2 - arcade/experimental/shadertoy_demo.py | 2 - arcade/experimental/shadertoy_demo_simple.py | 2 - arcade/experimental/shadertoy_textures.py | 2 - arcade/experimental/shadertoy_video_cv2.py | 2 - arcade/experimental/shapes_buffered_2_glow.py | 2 - arcade/experimental/shapes_perf.py | 2 - arcade/experimental/texture_transforms.py | 2 - arcade/future/background/__init__.py | 2 - arcade/future/background/background.py | 2 - .../future/background/background_texture.py | 2 - arcade/future/background/groups.py | 2 - arcade/future/input/input_manager_example.py | 2 - arcade/future/input/input_mapping.py | 2 - arcade/future/input/inputs.py | 2 - arcade/future/input/manager.py | 2 - arcade/future/input/raw_dicts.py | 2 - arcade/future/light/light_demo.py | 2 - arcade/future/light/light_demo_perf.py | 2 - arcade/future/light/lights.py | 2 - arcade/future/sub_clock.py | 2 - arcade/future/texture_render_target.py | 2 - arcade/future/video/video_cv2.py | 2 - arcade/future/video/video_player.py | 2 - arcade/future/video/video_record_cv2.py | 2 - arcade/geometry.py | 2 - arcade/gl/__init__.py | 2 - arcade/gl/enums.py | 2 - arcade/gl/exceptions.py | 2 - arcade/gl/geometry.py | 2 - arcade/gl/glsl.py | 2 - arcade/gl/program.py | 2 - arcade/gl/types.py | 2 - arcade/gl/uniform.py | 2 - arcade/gl/utils.py | 2 - arcade/gui/__init__.py | 2 - arcade/gui/constructs.py | 2 - arcade/gui/events.py | 2 - arcade/gui/experimental/password_input.py | 2 - arcade/gui/experimental/typed_text_input.py | 2 - arcade/gui/mixins.py | 2 - arcade/gui/nine_patch.py | 2 - arcade/gui/property.py | 2 - arcade/gui/style.py | 2 - arcade/gui/surface.py | 2 - arcade/gui/ui_manager.py | 2 - arcade/gui/view.py | 2 - arcade/gui/widgets/__init__.py | 1 - arcade/gui/widgets/buttons.py | 1 - arcade/gui/widgets/dropdown.py | 1 - arcade/gui/widgets/image.py | 1 - arcade/gui/widgets/text.py | 1 - arcade/gui/widgets/toggle.py | 1 - arcade/hitbox/__init__.py | 2 - arcade/hitbox/bounding_box.py | 2 - arcade/hitbox/pymunk.py | 2 - arcade/hitbox/simple.py | 2 - arcade/isometric.py | 2 - arcade/joysticks.py | 2 - arcade/key/__init__.py | 1 - arcade/management/__init__.py | 2 - arcade/math.py | 2 - arcade/particles/__init__.py | 2 - arcade/particles/emitter.py | 2 - arcade/particles/emitter_simple.py | 2 - arcade/particles/particle.py | 2 - arcade/paths.py | 2 - arcade/perf_graph.py | 2 - arcade/perf_info.py | 2 - arcade/physics_engines.py | 2 - arcade/pymunk_physics_engine.py | 2 - arcade/resources/__init__.py | 2 - arcade/scene.py | 2 - arcade/screenshot.py | 2 - arcade/shape_list.py | 2 - arcade/sound.py | 2 - arcade/sprite/__init__.py | 2 - arcade/sprite/animated.py | 2 - arcade/sprite/enums.py | 2 - arcade/sprite/mixins.py | 2 - arcade/sprite/sprite.py | 2 - arcade/sprite_list/__init__.py | 2 - arcade/sprite_list/collision.py | 2 - arcade/sprite_list/spatial_hash.py | 2 - arcade/text.py | 2 - arcade/texture/__init__.py | 2 - arcade/texture/generate.py | 2 - arcade/texture/loading.py | 2 - arcade/texture/manager.py | 2 - arcade/texture/tools.py | 2 - arcade/texture/transforms.py | 2 - arcade/texture_atlas/__init__.py | 2 - arcade/texture_atlas/atlas_array.py | 2 - arcade/texture_atlas/atlas_bindless.py | 2 - arcade/texture_atlas/helpers.py | 187 ------------------ arcade/texture_atlas/ref_counters.py | 2 - arcade/tilemap/__init__.py | 2 - arcade/types/__init__.py | 2 - arcade/types/numbers.py | 2 - arcade/types/vector_like.py | 2 - arcade/utils.py | 2 - arcade/version.py | 2 - benchmarks/sprite/sprite_alt.py | 2 - doc/conf.py | 2 - make.py | 2 - pyproject.toml | 3 +- tests/conftest.py | 2 - .../sprite_collision_inspector.py | 2 - tests/unit/gui/__init__.py | 2 - tests/unit/rect/test_rect_creation_helpers.py | 2 - util/create_resources_listing.py | 2 - util/doc_helpers/import_resolver.py | 2 - util/doc_helpers/real_filesystem.py | 2 - util/doc_helpers/vfs.py | 2 - util/update_quick_index.py | 2 - 168 files changed, 8 insertions(+), 620 deletions(-) delete mode 100644 arcade/experimental/atlas_load_save.py delete mode 100644 arcade/texture_atlas/helpers.py diff --git a/.github/workflows/selfhosted_runner.yml b/.github/workflows/selfhosted_runner.yml index 7d672e7672..c0caacd8b7 100644 --- a/.github/workflows/selfhosted_runner.yml +++ b/.github/workflows/selfhosted_runner.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ['3.9.13', '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.10', '3.11', '3.12', '3.13'] architecture: ['x64'] steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f33b004d4..9ee2958e48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,12 @@ You can grab pre-release versions from PyPi. See the available versions from the Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page. -## Version 3.0.2 (unreleased) + +## Version 3.1 (unreleased) + +- Drop Python 3.9 support + +## Version 3.0.2 ### Improvements diff --git a/arcade/__init__.py b/arcade/__init__.py index e687956869..9847337199 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -4,8 +4,6 @@ A Python simple, easy to use module for creating 2D games. """ -from __future__ import annotations - # flake8: noqa: E402 # Error out if we import Arcade with an incompatible version of Python. import sys diff --git a/arcade/__main__.py b/arcade/__main__.py index 62409a6fd0..1a318f0781 100644 --- a/arcade/__main__.py +++ b/arcade/__main__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from arcade.management import show_info if __name__ == "__main__": diff --git a/arcade/__pyinstaller/__init__.py b/arcade/__pyinstaller/__init__.py index 9309da9cc5..1c52aadf4b 100644 --- a/arcade/__pyinstaller/__init__.py +++ b/arcade/__pyinstaller/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import os diff --git a/arcade/__pyinstaller/hook-arcade.py b/arcade/__pyinstaller/hook-arcade.py index 9035f95b7c..76f89a4932 100644 --- a/arcade/__pyinstaller/hook-arcade.py +++ b/arcade/__pyinstaller/hook-arcade.py @@ -10,8 +10,6 @@ https://api.arcade.academy/en/latest/tutorials/bundling_with_pyinstaller/index.html """ -from __future__ import annotations - from importlib.util import find_spec from pathlib import Path diff --git a/arcade/cache/__init__.py b/arcade/cache/__init__.py index f0aa68c6b8..33e67538a4 100644 --- a/arcade/cache/__init__.py +++ b/arcade/cache/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Any from .hit_box import HitBoxCache from .texture import TextureCache diff --git a/arcade/cache/texture.py b/arcade/cache/texture.py index 2ed64e950b..4f1008dca0 100644 --- a/arcade/cache/texture.py +++ b/arcade/cache/texture.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path from typing import TYPE_CHECKING diff --git a/arcade/camera/data_types.py b/arcade/camera/data_types.py index 2291c4f564..c67b90c32c 100644 --- a/arcade/camera/data_types.py +++ b/arcade/camera/data_types.py @@ -4,8 +4,6 @@ wide usage throughout Arcade's camera code. """ -from __future__ import annotations - from contextlib import contextmanager from typing import Final, Generator, Protocol diff --git a/arcade/camera/grips/position.py b/arcade/camera/grips/position.py index ebc3dcb2ef..2f22c25bc9 100644 --- a/arcade/camera/grips/position.py +++ b/arcade/camera/grips/position.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pyglet.math import Vec3 from arcade.camera import CameraData diff --git a/arcade/camera/grips/rotate.py b/arcade/camera/grips/rotate.py index 4d70f199fc..02432ec420 100644 --- a/arcade/camera/grips/rotate.py +++ b/arcade/camera/grips/rotate.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pyglet.math import Vec3 from arcade.camera.data_types import CameraData diff --git a/arcade/camera/grips/screen_shake_2d.py b/arcade/camera/grips/screen_shake_2d.py index b51fbbee34..eb51fa7516 100644 --- a/arcade/camera/grips/screen_shake_2d.py +++ b/arcade/camera/grips/screen_shake_2d.py @@ -3,8 +3,6 @@ Provides an easy way to cause a camera to shake. """ -from __future__ import annotations - from math import exp, floor, log, pi, sin from random import randint, uniform diff --git a/arcade/camera/grips/strafe.py b/arcade/camera/grips/strafe.py index 3d3ffc5d33..30eafe0247 100644 --- a/arcade/camera/grips/strafe.py +++ b/arcade/camera/grips/strafe.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pyglet.math import Vec3 from arcade.camera.data_types import CameraData diff --git a/arcade/camera/projection_functions.py b/arcade/camera/projection_functions.py index 5321b7e21f..dda0fb4f6e 100644 --- a/arcade/camera/projection_functions.py +++ b/arcade/camera/projection_functions.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from math import pi, tan from pyglet.math import Mat4, Vec2, Vec3, Vec4 diff --git a/arcade/clock.py b/arcade/clock.py index 967b7c2f78..1ebb20e597 100644 --- a/arcade/clock.py +++ b/arcade/clock.py @@ -1,5 +1,3 @@ -from __future__ import annotations - __all__ = ( "Clock", "FixedClock", diff --git a/arcade/color/__init__.py b/arcade/color/__init__.py index 23ebf27dcd..2cfe51e998 100644 --- a/arcade/color/__init__.py +++ b/arcade/color/__init__.py @@ -2,8 +2,6 @@ This module pre-defines several colors. """ -from __future__ import annotations - from arcade.types import Color AERO_BLUE = Color(201, 255, 229, 255) diff --git a/arcade/context.py b/arcade/context.py index 8ca0b58749..56164afc4d 100644 --- a/arcade/context.py +++ b/arcade/context.py @@ -3,8 +3,6 @@ Contains pre-loaded programs """ -from __future__ import annotations - from pathlib import Path from typing import Any, Iterable, Sequence diff --git a/arcade/controller.py b/arcade/controller.py index 10d5e8f098..0e096f8e9f 100644 --- a/arcade/controller.py +++ b/arcade/controller.py @@ -5,8 +5,6 @@ https://pyglet.readthedocs.io/en/latest/programming_guide/input.html#using-controllers """ -from __future__ import annotations - import pyglet.input __all__ = ["get_controllers", "ControllerManager"] diff --git a/arcade/csscolor/__init__.py b/arcade/csscolor/__init__.py index 67f633ecd7..a19aad3f3f 100644 --- a/arcade/csscolor/__init__.py +++ b/arcade/csscolor/__init__.py @@ -3,8 +3,6 @@ https://www.w3.org/TR/2018/PR-css-color-3-20180315/ """ -from __future__ import annotations - from arcade.types import Color ALICE_BLUE = Color(240, 248, 255, 255) diff --git a/arcade/draw/rect.py b/arcade/draw/rect.py index eb87f6e21d..c7790d68b4 100644 --- a/arcade/draw/rect.py +++ b/arcade/draw/rect.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import array from arcade import gl diff --git a/arcade/earclip.py b/arcade/earclip.py index c00e5d4da6..8d071f965d 100644 --- a/arcade/earclip.py +++ b/arcade/earclip.py @@ -3,8 +3,6 @@ from: https://github.com/linuxlewis/tripy/blob/master/tripy.py """ -from __future__ import annotations - from arcade.types import Point2, Point2List diff --git a/arcade/easing.py b/arcade/easing.py index 3d69dee3b5..2ce734dee9 100644 --- a/arcade/easing.py +++ b/arcade/easing.py @@ -2,8 +2,6 @@ Functions used to support easing """ -from __future__ import annotations - from dataclasses import dataclass from math import cos, pi, sin from typing import Callable diff --git a/arcade/examples/depth_of_field.py b/arcade/examples/depth_of_field.py index e1fcf40515..a3c8f7f882 100644 --- a/arcade/examples/depth_of_field.py +++ b/arcade/examples/depth_of_field.py @@ -21,8 +21,6 @@ python -m arcade.examples.depth_of_field """ -from __future__ import annotations - from contextlib import contextmanager from math import cos, pi from random import randint, uniform diff --git a/arcade/examples/gui/2_widgets.py b/arcade/examples/gui/2_widgets.py index 973963f23b..7a15819d55 100644 --- a/arcade/examples/gui/2_widgets.py +++ b/arcade/examples/gui/2_widgets.py @@ -6,8 +6,6 @@ python -m arcade.examples.gui.2_widgets """ -from __future__ import annotations - import textwrap from copy import deepcopy diff --git a/arcade/examples/gui/3_buttons.py b/arcade/examples/gui/3_buttons.py index e33373b72f..d628feb185 100644 --- a/arcade/examples/gui/3_buttons.py +++ b/arcade/examples/gui/3_buttons.py @@ -8,8 +8,6 @@ python -m arcade.examples.gui.3_buttons """ -from __future__ import annotations - import arcade from arcade.gui import ( UIAnchorLayout, diff --git a/arcade/examples/gui/4_with_camera.py b/arcade/examples/gui/4_with_camera.py index 6a5325b156..ab4245ba64 100644 --- a/arcade/examples/gui/4_with_camera.py +++ b/arcade/examples/gui/4_with_camera.py @@ -10,8 +10,6 @@ python -m arcade.examples.gui.4_with_camera """ -from __future__ import annotations - import math import random from typing import Optional diff --git a/arcade/examples/gui/6_size_hints.py b/arcade/examples/gui/6_size_hints.py index e9196b99a9..6f95713118 100644 --- a/arcade/examples/gui/6_size_hints.py +++ b/arcade/examples/gui/6_size_hints.py @@ -17,8 +17,6 @@ python -m arcade.examples.gui.6_size_hints """ -from __future__ import annotations - import textwrap import arcade diff --git a/arcade/examples/gui/exp_hidden_password.py b/arcade/examples/gui/exp_hidden_password.py index 722abb692b..8c83ffeff5 100644 --- a/arcade/examples/gui/exp_hidden_password.py +++ b/arcade/examples/gui/exp_hidden_password.py @@ -12,8 +12,6 @@ python -m arcade.examples.gui.exp_hidden_password """ -from __future__ import annotations - import arcade from arcade.gui import UIInputText, UIOnClickEvent, UIView from arcade.gui.experimental.password_input import UIPasswordInput diff --git a/arcade/examples/gui/exp_restricted_input.py b/arcade/examples/gui/exp_restricted_input.py index 1611cc798f..bfa6d8deb8 100644 --- a/arcade/examples/gui/exp_restricted_input.py +++ b/arcade/examples/gui/exp_restricted_input.py @@ -4,8 +4,6 @@ python -m arcade.examples.gui.exp_restricted_input """ -from __future__ import annotations - import arcade from arcade.gui import UIAnchorLayout, UIBoxLayout, UIView from arcade.gui.experimental.restricted_input import UIIntInput diff --git a/arcade/examples/gui/exp_scroll_area.py b/arcade/examples/gui/exp_scroll_area.py index 7b035fb7a3..49463bc6c5 100644 --- a/arcade/examples/gui/exp_scroll_area.py +++ b/arcade/examples/gui/exp_scroll_area.py @@ -9,9 +9,6 @@ python -m arcade.examples.gui.exp_scroll_area """ -from __future__ import annotations - - import arcade from arcade.gui import UIAnchorLayout, UIBoxLayout, UIFlatButton, UIView from arcade.gui.experimental import UIScrollArea diff --git a/arcade/examples/gui/ninepatch.py b/arcade/examples/gui/ninepatch.py index 25239bf259..644c1b6967 100644 --- a/arcade/examples/gui/ninepatch.py +++ b/arcade/examples/gui/ninepatch.py @@ -9,8 +9,6 @@ python -m arcade.examples.gui.ninepatch """ -from __future__ import annotations - import arcade from arcade import load_texture from arcade.gui import UIManager, UIAnchorLayout, UIWidget, NinePatchTexture diff --git a/arcade/examples/gui/own_layout.py b/arcade/examples/gui/own_layout.py index 8550e43892..8b0dea84cb 100644 --- a/arcade/examples/gui/own_layout.py +++ b/arcade/examples/gui/own_layout.py @@ -8,8 +8,6 @@ python -m arcade.examples.gui.own_layout """ -from __future__ import annotations - from math import cos, sin from typing import TypeVar diff --git a/arcade/examples/gui/own_widget.py b/arcade/examples/gui/own_widget.py index 715bb8f4c8..befc5cb6ce 100644 --- a/arcade/examples/gui/own_widget.py +++ b/arcade/examples/gui/own_widget.py @@ -22,8 +22,6 @@ python -m arcade.examples.gui.own_widgets """ -from __future__ import annotations - import arcade from arcade.gui import Property, UIAnchorLayout, UIBoxLayout, UISpace, UIView, UIWidget, bind from arcade.types import Color diff --git a/arcade/examples/particle_fireworks.py b/arcade/examples/particle_fireworks.py index 2e44f21fff..caef7117f6 100644 --- a/arcade/examples/particle_fireworks.py +++ b/arcade/examples/particle_fireworks.py @@ -6,7 +6,6 @@ If Python and Arcade are installed, this example can be run from the command line with: python -m arcade.examples.particle_fireworks """ -from __future__ import annotations import random import pyglet diff --git a/arcade/examples/performance_statistics.py b/arcade/examples/performance_statistics.py index 3360ae9552..f117f42918 100644 --- a/arcade/examples/performance_statistics.py +++ b/arcade/examples/performance_statistics.py @@ -19,7 +19,6 @@ command line with: python -m arcade.examples.performance_statistics """ -from __future__ import annotations import random import arcade diff --git a/arcade/examples/pymunk_demo_top_down.py b/arcade/examples/pymunk_demo_top_down.py index 65b73c795c..0cef3abc47 100644 --- a/arcade/examples/pymunk_demo_top_down.py +++ b/arcade/examples/pymunk_demo_top_down.py @@ -5,7 +5,6 @@ If Python and Arcade are installed, this example can be run from the command line with: python -m arcade.examples.pymunk_demo_top_down """ -from __future__ import annotations import math import random import arcade diff --git a/arcade/examples/sections_demo_1.py b/arcade/examples/sections_demo_1.py index ac314aa461..9f42df9586 100644 --- a/arcade/examples/sections_demo_1.py +++ b/arcade/examples/sections_demo_1.py @@ -16,8 +16,6 @@ python -m arcade.examples.sections_demo_1 """ -from __future__ import annotations - import arcade from arcade import SectionManager diff --git a/arcade/examples/sections_demo_3.py b/arcade/examples/sections_demo_3.py index e7d657339b..a05640b0cd 100644 --- a/arcade/examples/sections_demo_3.py +++ b/arcade/examples/sections_demo_3.py @@ -22,8 +22,6 @@ python -m arcade.examples.sections_demo_3 """ -from __future__ import annotations - from math import sqrt import arcade diff --git a/arcade/examples/sprite_depth_cosine.py b/arcade/examples/sprite_depth_cosine.py index ef519a66aa..82c9dea9fb 100644 --- a/arcade/examples/sprite_depth_cosine.py +++ b/arcade/examples/sprite_depth_cosine.py @@ -14,8 +14,6 @@ python -m arcade.examples.sprite_depth_cosine """ -from __future__ import annotations - import math from pyglet.graphics import Batch diff --git a/arcade/examples/threaded_loading.py b/arcade/examples/threaded_loading.py index 494d2ade15..b79ee25e47 100644 --- a/arcade/examples/threaded_loading.py +++ b/arcade/examples/threaded_loading.py @@ -26,8 +26,6 @@ If Python and Arcade are installed, this example can be run from the command line with: python -m arcade.examples.threaded_loading """ -from __future__ import annotations - import sys from time import sleep diff --git a/arcade/experimental/__init__.py b/arcade/experimental/__init__.py index 34cfea8e19..df282fc342 100644 --- a/arcade/experimental/__init__.py +++ b/arcade/experimental/__init__.py @@ -2,8 +2,6 @@ Experimental stuff. API may change. """ -from __future__ import annotations - from .shadertoy import Shadertoy, ShadertoyBuffer, ShadertoyBase from .crt_filter import CRTFilter from .bloom_filter import BloomFilter diff --git a/arcade/experimental/atlas_load_save.py b/arcade/experimental/atlas_load_save.py deleted file mode 100644 index 1e102df6df..0000000000 --- a/arcade/experimental/atlas_load_save.py +++ /dev/null @@ -1,112 +0,0 @@ -# """ -# Quick and dirty atlas load/save testing. -# Loading and saving atlases are not officially supported. -# This is simply an experiment. - -# Dump atlas: -# python arcade/experimental/atlas_load_save.py save - -# Load atlas: -# python arcade/experimental/atlas_load_save.py load -# """ - -# from __future__ import annotations - -# import sys -# import math -# import pprint -# from typing import Dict, Tuple, List -# from time import perf_counter -# from pathlib import Path -# import arcade -# from arcade.texture_atlas.helpers import save_atlas, load_atlas - -# MODE = 'save' -# RESOURCE_ROOT = arcade.resources.ASSET_PATH -# DESTINATION = Path.cwd() - -# texture_paths: List[Path] = [] -# texture_paths += RESOURCE_ROOT.glob("images/enemies/*.png") -# texture_paths += RESOURCE_ROOT.glob("images/items/*.png") -# texture_paths += RESOURCE_ROOT.glob("images/alien/*.png") -# texture_paths += RESOURCE_ROOT.glob("images/tiles/*.png") - - -# def populate_atlas(atlas: arcade.TextureAtlas) -> Tuple[int, Dict[str, float]]: -# """Populate the atlas with all the resources we can find""" -# perf_data = {} -# textures = [] -# t = perf_counter() -# for path in texture_paths: -# texture = arcade.load_texture(path, hit_box_algorithm=arcade.hitbox.algo_simple) -# textures.append(texture) -# perf_data['load_textures'] = perf_counter() - t - -# t = perf_counter() -# for texture in textures: -# atlas.add(texture) -# perf_data['add_textures'] = perf_counter() - t - -# return len(textures), perf_data - - -# class AtlasLoadSave(arcade.Window): -# """ -# This class demonstrates how to load and save texture atlases. -# """ - -# def __init__(self): -# super().__init__(1280, 720, "Atlas Load Save") -# self.done = False - -# if MODE == "save": -# t = perf_counter() -# self.atlas = arcade.TextureAtlas((1024, 1024)) -# count, perf_data = populate_atlas(self.atlas) -# print(f'Populated atlas with {count} texture in {perf_counter() - t:.2f} seconds') -# save_atlas( -# self.atlas, -# directory=Path.cwd(), -# name="test", -# resource_root=RESOURCE_ROOT, -# ) -# self.done = True -# if MODE == "load": -# t = perf_counter() -# self.atlas, perf_data = load_atlas(Path.cwd() / 'test.json', RESOURCE_ROOT) -# print(f'Loaded atlas in {perf_counter() - t:.2f} seconds') -# pprint.pprint(perf_data, indent=2) -# # self.done = True - -# # Make a sprite for each texture -# self.sp = arcade.SpriteList(atlas=self.atlas) -# for i, texture in enumerate(self.atlas.textures): -# pos = i * 64 -# sprite = arcade.Sprite( -# texture, -# center_x=32 + math.fmod(pos, self.width), -# center_y=32 + math.floor(pos / self.width) * 64, -# scale=0.45, -# ) -# self.sp.append(sprite) - -# print(f'Atlas has {len(self.atlas._textures)} textures') - -# # self.atlas.show(draw_borders=True) - -# def on_draw(self): -# self.clear() -# self.sp.draw(pixelated=True) - -# def on_update(self, delta_time: float): -# if self.done: -# self.close() - - -# if len(sys.argv) < 2 or sys.argv[1] not in ('load', 'save'): -# print('Usage: atlas_load_save.py [save|load]') -# sys.exit(1) - -# MODE = sys.argv[1] - -# AtlasLoadSave().run() diff --git a/arcade/experimental/atlas_render_into.py b/arcade/experimental/atlas_render_into.py index 23ddfcc78c..d527dd2a39 100644 --- a/arcade/experimental/atlas_render_into.py +++ b/arcade/experimental/atlas_render_into.py @@ -2,8 +2,6 @@ Render into a sub-section of a texture atlas """ -from __future__ import annotations - import math import arcade diff --git a/arcade/experimental/atlas_replace_image.py b/arcade/experimental/atlas_replace_image.py index 3a1d949e5a..8bd284419b 100644 --- a/arcade/experimental/atlas_replace_image.py +++ b/arcade/experimental/atlas_replace_image.py @@ -5,8 +5,6 @@ over time at (not too frequently) we can update the underlying atlas directly. """ -from __future__ import annotations - from itertools import cycle import arcade diff --git a/arcade/experimental/bloom_filter.py b/arcade/experimental/bloom_filter.py index dc9fffe8df..7f380d9c5c 100644 --- a/arcade/experimental/bloom_filter.py +++ b/arcade/experimental/bloom_filter.py @@ -2,8 +2,6 @@ See: https://www.shadertoy.com/view/lsBfRc """ -from __future__ import annotations - from arcade.experimental import Shadertoy diff --git a/arcade/experimental/crt_filter.py b/arcade/experimental/crt_filter.py index 10667a4141..02cde40908 100644 --- a/arcade/experimental/crt_filter.py +++ b/arcade/experimental/crt_filter.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pyglet.math import Vec2 from arcade.experimental import Shadertoy diff --git a/arcade/experimental/gaussian_kernel.py b/arcade/experimental/gaussian_kernel.py index 4b219b3446..c39563b0aa 100644 --- a/arcade/experimental/gaussian_kernel.py +++ b/arcade/experimental/gaussian_kernel.py @@ -4,8 +4,6 @@ https://observablehq.com/@jobleonard/gaussian-kernel-calculater """ -from __future__ import annotations - import math SQRT2 = math.sqrt(2) diff --git a/arcade/experimental/geo_culling_check.py b/arcade/experimental/geo_culling_check.py index 1193b8cff6..ef76fb8754 100644 --- a/arcade/experimental/geo_culling_check.py +++ b/arcade/experimental/geo_culling_check.py @@ -6,8 +6,6 @@ Simply run the program and move draw the sprites around using the mouse. """ -from __future__ import annotations - import PIL from pyglet.math import Mat4 diff --git a/arcade/experimental/postprocessing.py b/arcade/experimental/postprocessing.py index bc6a0e7a12..b98278c938 100644 --- a/arcade/experimental/postprocessing.py +++ b/arcade/experimental/postprocessing.py @@ -2,8 +2,6 @@ Post-processing shaders. """ -from __future__ import annotations - from arcade import get_window from arcade.context import ArcadeContext from arcade.experimental.gaussian_kernel import gaussian_kernel diff --git a/arcade/experimental/profiling.py b/arcade/experimental/profiling.py index 7807b3b021..26e3d40037 100644 --- a/arcade/experimental/profiling.py +++ b/arcade/experimental/profiling.py @@ -2,8 +2,6 @@ Simple experimental profiler. This api is not stable. """ -from __future__ import annotations - import cProfile import pstats from contextlib import contextmanager diff --git a/arcade/experimental/pygame_interaction.py b/arcade/experimental/pygame_interaction.py index 308d9e0611..fa224abed7 100644 --- a/arcade/experimental/pygame_interaction.py +++ b/arcade/experimental/pygame_interaction.py @@ -13,8 +13,6 @@ """ -from __future__ import annotations - import math import pygame # type: ignore diff --git a/arcade/experimental/query_demo.py b/arcade/experimental/query_demo.py index 1439cdafbb..42a7222460 100644 --- a/arcade/experimental/query_demo.py +++ b/arcade/experimental/query_demo.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import math import time diff --git a/arcade/experimental/render_offscreen_animated.py b/arcade/experimental/render_offscreen_animated.py index 7af10484b3..ad8a2b7943 100644 --- a/arcade/experimental/render_offscreen_animated.py +++ b/arcade/experimental/render_offscreen_animated.py @@ -5,8 +5,6 @@ python -m arcade.examples.shape_list_skylines """ -from __future__ import annotations - import random import time diff --git a/arcade/experimental/shadertoy.py b/arcade/experimental/shadertoy.py index b304fc473a..ca13c53b86 100644 --- a/arcade/experimental/shadertoy.py +++ b/arcade/experimental/shadertoy.py @@ -15,8 +15,6 @@ uniform float iSampleRate; // sound sample rate (i.e., 44100) """ -from __future__ import annotations - import string from datetime import datetime from pathlib import Path diff --git a/arcade/experimental/shadertoy_demo.py b/arcade/experimental/shadertoy_demo.py index cb83416935..35ac1d0db4 100644 --- a/arcade/experimental/shadertoy_demo.py +++ b/arcade/experimental/shadertoy_demo.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path import arcade diff --git a/arcade/experimental/shadertoy_demo_simple.py b/arcade/experimental/shadertoy_demo_simple.py index f9423aecbf..cad3087e23 100644 --- a/arcade/experimental/shadertoy_demo_simple.py +++ b/arcade/experimental/shadertoy_demo_simple.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import arcade from arcade.experimental.shadertoy import Shadertoy diff --git a/arcade/experimental/shadertoy_textures.py b/arcade/experimental/shadertoy_textures.py index 8f06deb6f3..78ac2f9062 100644 --- a/arcade/experimental/shadertoy_textures.py +++ b/arcade/experimental/shadertoy_textures.py @@ -3,8 +3,6 @@ We simply mix the two texture layers. """ -from __future__ import annotations - import arcade from arcade.experimental.shadertoy import Shadertoy diff --git a/arcade/experimental/shadertoy_video_cv2.py b/arcade/experimental/shadertoy_video_cv2.py index 581231170a..7dfb033ff3 100644 --- a/arcade/experimental/shadertoy_video_cv2.py +++ b/arcade/experimental/shadertoy_video_cv2.py @@ -6,8 +6,6 @@ """ -from __future__ import annotations - import cv2 # type: ignore import arcade diff --git a/arcade/experimental/shapes_buffered_2_glow.py b/arcade/experimental/shapes_buffered_2_glow.py index 452c3aa0fc..2abc284e8b 100644 --- a/arcade/experimental/shapes_buffered_2_glow.py +++ b/arcade/experimental/shapes_buffered_2_glow.py @@ -7,8 +7,6 @@ python -m arcade.examples.shapes_buffered """ -from __future__ import annotations - import random from pyglet import gl diff --git a/arcade/experimental/shapes_perf.py b/arcade/experimental/shapes_perf.py index f339543ed4..b4dc8f5c65 100644 --- a/arcade/experimental/shapes_perf.py +++ b/arcade/experimental/shapes_perf.py @@ -2,8 +2,6 @@ This is for testing geometry shader shapes. Please keep. """ -from __future__ import annotations - import math import random import time diff --git a/arcade/experimental/texture_transforms.py b/arcade/experimental/texture_transforms.py index 88ebb283f3..27b4cc9c0e 100644 --- a/arcade/experimental/texture_transforms.py +++ b/arcade/experimental/texture_transforms.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import random import arcade diff --git a/arcade/future/background/__init__.py b/arcade/future/background/__init__.py index ad3bc3d588..22e701ba75 100644 --- a/arcade/future/background/__init__.py +++ b/arcade/future/background/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Tuple from PIL import Image diff --git a/arcade/future/background/background.py b/arcade/future/background/background.py index 58054b2c5a..e75177fe80 100644 --- a/arcade/future/background/background.py +++ b/arcade/future/background/background.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import arcade.gl as gl from arcade.future.background import BackgroundTexture from arcade.window_commands import get_window diff --git a/arcade/future/background/background_texture.py b/arcade/future/background/background_texture.py index 6db7fdf37b..ec15360a9a 100644 --- a/arcade/future/background/background_texture.py +++ b/arcade/future/background/background_texture.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from PIL import Image from pyglet.math import Mat3 diff --git a/arcade/future/background/groups.py b/arcade/future/background/groups.py index b6ee801631..081bd09a83 100644 --- a/arcade/future/background/groups.py +++ b/arcade/future/background/groups.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import arcade.gl as gl from arcade.future.background import Background diff --git a/arcade/future/input/input_manager_example.py b/arcade/future/input/input_manager_example.py index 87e573054a..b71f5e5337 100644 --- a/arcade/future/input/input_manager_example.py +++ b/arcade/future/input/input_manager_example.py @@ -1,6 +1,4 @@ # type: ignore -from __future__ import annotations - import random from typing import Optional, Sequence diff --git a/arcade/future/input/input_mapping.py b/arcade/future/input/input_mapping.py index d4caeed990..19e21b937b 100644 --- a/arcade/future/input/input_mapping.py +++ b/arcade/future/input/input_mapping.py @@ -1,7 +1,5 @@ # type: ignore -from __future__ import annotations - from arcade.future.input import inputs from arcade.future.input.raw_dicts import RawAction, RawActionMapping, RawAxis, RawAxisMapping diff --git a/arcade/future/input/inputs.py b/arcade/future/input/inputs.py index e6b8b764b0..add46e8237 100644 --- a/arcade/future/input/inputs.py +++ b/arcade/future/input/inputs.py @@ -5,8 +5,6 @@ However Controller buttons and axes are mapped to their Pyglet string values. """ -from __future__ import annotations - from enum import Enum, auto from sys import platform from typing import Type diff --git a/arcade/future/input/manager.py b/arcade/future/input/manager.py index 104a6635d9..ed4fe907a4 100644 --- a/arcade/future/input/manager.py +++ b/arcade/future/input/manager.py @@ -1,6 +1,4 @@ # type: ignore -from __future__ import annotations - from enum import Enum from typing import Any, Callable, TypeVar diff --git a/arcade/future/input/raw_dicts.py b/arcade/future/input/raw_dicts.py index 5f44fc2c4f..7ec453982a 100644 --- a/arcade/future/input/raw_dicts.py +++ b/arcade/future/input/raw_dicts.py @@ -3,8 +3,6 @@ Placing them here prevents circular import issues. """ -from __future__ import annotations - from typing import Union from typing_extensions import TypedDict diff --git a/arcade/future/light/light_demo.py b/arcade/future/light/light_demo.py index f3114d960a..cfdedd3dcf 100644 --- a/arcade/future/light/light_demo.py +++ b/arcade/future/light/light_demo.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import math import arcade diff --git a/arcade/future/light/light_demo_perf.py b/arcade/future/light/light_demo_perf.py index 5611d032fd..e0684fb392 100644 --- a/arcade/future/light/light_demo_perf.py +++ b/arcade/future/light/light_demo_perf.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import math import random diff --git a/arcade/future/light/lights.py b/arcade/future/light/lights.py index e792ef4b0c..42fb51e45e 100644 --- a/arcade/future/light/lights.py +++ b/arcade/future/light/lights.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from array import array from typing import Iterator, Sequence diff --git a/arcade/future/sub_clock.py b/arcade/future/sub_clock.py index 72ad712133..11c8df7624 100644 --- a/arcade/future/sub_clock.py +++ b/arcade/future/sub_clock.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Optional, Union from arcade.clock import GLOBAL_CLOCK, Clock diff --git a/arcade/future/texture_render_target.py b/arcade/future/texture_render_target.py index 96fbed491b..88cb5e1e3d 100644 --- a/arcade/future/texture_render_target.py +++ b/arcade/future/texture_render_target.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from arcade import get_window from arcade.color import TRANSPARENT_BLACK from arcade.gl import geometry diff --git a/arcade/future/video/video_cv2.py b/arcade/future/video/video_cv2.py index 6ef9c610cd..6f38a3a538 100644 --- a/arcade/future/video/video_cv2.py +++ b/arcade/future/video/video_cv2.py @@ -9,8 +9,6 @@ pip install opencv-python """ -from __future__ import annotations - from math import floor from pathlib import Path diff --git a/arcade/future/video/video_player.py b/arcade/future/video/video_player.py index 548f16c1ec..4962011ae6 100644 --- a/arcade/future/video/video_player.py +++ b/arcade/future/video/video_player.py @@ -5,8 +5,6 @@ and you might need to tell pyglet where it's located. """ -from __future__ import annotations - from pathlib import Path # import sys diff --git a/arcade/future/video/video_record_cv2.py b/arcade/future/video/video_record_cv2.py index 69309c988c..9dd7089f62 100644 --- a/arcade/future/video/video_record_cv2.py +++ b/arcade/future/video/video_record_cv2.py @@ -19,8 +19,6 @@ pip install opencv-python numpy """ -from __future__ import annotations - import cv2 # type: ignore import numpy # type: ignore import pyglet.gl as gl diff --git a/arcade/geometry.py b/arcade/geometry.py index 22b8e3dbaf..3a60abc779 100644 --- a/arcade/geometry.py +++ b/arcade/geometry.py @@ -6,8 +6,6 @@ Point in polygon function from https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/ """ -from __future__ import annotations - from sys import maxsize as sys_int_maxsize from arcade.types import Point2, Point2List diff --git a/arcade/gl/__init__.py b/arcade/gl/__init__.py index e669428fea..ad05c7c84a 100644 --- a/arcade/gl/__init__.py +++ b/arcade/gl/__init__.py @@ -15,8 +15,6 @@ and is only recommended for more advanced users """ -from __future__ import annotations - from .context import Context from .types import BufferDescription from .compute_shader import ComputeShader diff --git a/arcade/gl/enums.py b/arcade/gl/enums.py index 9d87a2cdcb..775fec45a0 100644 --- a/arcade/gl/enums.py +++ b/arcade/gl/enums.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pyglet import gl # Texture min/mag filters diff --git a/arcade/gl/exceptions.py b/arcade/gl/exceptions.py index c90ded6c35..ad9d20ef14 100644 --- a/arcade/gl/exceptions.py +++ b/arcade/gl/exceptions.py @@ -1,5 +1,3 @@ -from __future__ import annotations - class ShaderException(Exception): """Exception class for shader-specific problems.""" diff --git a/arcade/gl/geometry.py b/arcade/gl/geometry.py index 697adf59a7..524d6930b1 100644 --- a/arcade/gl/geometry.py +++ b/arcade/gl/geometry.py @@ -2,8 +2,6 @@ A module providing commonly used geometry """ -from __future__ import annotations - import math from array import array diff --git a/arcade/gl/glsl.py b/arcade/gl/glsl.py index ad3bb54119..61580bb6a5 100644 --- a/arcade/gl/glsl.py +++ b/arcade/gl/glsl.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import re from typing import TYPE_CHECKING, Iterable diff --git a/arcade/gl/program.py b/arcade/gl/program.py index 27d05504cc..b75a91a790 100644 --- a/arcade/gl/program.py +++ b/arcade/gl/program.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import typing import weakref from ctypes import ( diff --git a/arcade/gl/types.py b/arcade/gl/types.py index 190ea147ad..1c7e4589fc 100644 --- a/arcade/gl/types.py +++ b/arcade/gl/types.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import re from typing import Iterable, Sequence, Union diff --git a/arcade/gl/uniform.py b/arcade/gl/uniform.py index 6ca4af7472..bf4584e920 100644 --- a/arcade/gl/uniform.py +++ b/arcade/gl/uniform.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import struct from ctypes import POINTER, c_double, c_float, c_int, c_uint, cast diff --git a/arcade/gl/utils.py b/arcade/gl/utils.py index 06a4a14663..cf3249cb3f 100644 --- a/arcade/gl/utils.py +++ b/arcade/gl/utils.py @@ -2,8 +2,6 @@ Various utility functions for the gl module. """ -from __future__ import annotations - from array import array from ctypes import c_byte from typing import Any diff --git a/arcade/gui/__init__.py b/arcade/gui/__init__.py index 231438c00f..693974f52f 100644 --- a/arcade/gui/__init__.py +++ b/arcade/gui/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from arcade.gui.constructs import UIMessageBox, UIButtonRow from arcade.gui.events import UIEvent from arcade.gui.events import UIKeyEvent diff --git a/arcade/gui/constructs.py b/arcade/gui/constructs.py index 4dcc24d5d3..88ea1767a2 100644 --- a/arcade/gui/constructs.py +++ b/arcade/gui/constructs.py @@ -1,7 +1,5 @@ """Constructs, are prepared widget combinations, you can use for common use-cases""" -from __future__ import annotations - from typing import Any, Optional import arcade diff --git a/arcade/gui/events.py b/arcade/gui/events.py index 03bb97bbf8..a150d1ce5a 100644 --- a/arcade/gui/events.py +++ b/arcade/gui/events.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from dataclasses import dataclass from typing import Any diff --git a/arcade/gui/experimental/password_input.py b/arcade/gui/experimental/password_input.py index c0cbd3ecee..afed0f6f2e 100644 --- a/arcade/gui/experimental/password_input.py +++ b/arcade/gui/experimental/password_input.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Optional from arcade.gui import Surface, UIEvent, UIInputText, UITextInputEvent diff --git a/arcade/gui/experimental/typed_text_input.py b/arcade/gui/experimental/typed_text_input.py index 3d3c8d2b35..ed2fff5db6 100644 --- a/arcade/gui/experimental/typed_text_input.py +++ b/arcade/gui/experimental/typed_text_input.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Callable, Generic, Optional, Type, TypeVar, cast import arcade diff --git a/arcade/gui/mixins.py b/arcade/gui/mixins.py index c7f27d9ed3..8044cdebdd 100644 --- a/arcade/gui/mixins.py +++ b/arcade/gui/mixins.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import Optional from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED diff --git a/arcade/gui/nine_patch.py b/arcade/gui/nine_patch.py index 881b783805..4481f95423 100644 --- a/arcade/gui/nine_patch.py +++ b/arcade/gui/nine_patch.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import arcade import arcade.gl as gl from arcade.texture_atlas.base import TextureAtlasBase diff --git a/arcade/gui/property.py b/arcade/gui/property.py index 03e54419a9..95e46ee244 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import sys import traceback from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, cast diff --git a/arcade/gui/style.py b/arcade/gui/style.py index 7f9304914b..674894193f 100644 --- a/arcade/gui/style.py +++ b/arcade/gui/style.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from abc import abstractmethod from dataclasses import dataclass from typing import Any, Generic, TypeVar, overload diff --git a/arcade/gui/surface.py b/arcade/gui/surface.py index ab1b5c958a..370d1c2090 100644 --- a/arcade/gui/surface.py +++ b/arcade/gui/surface.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from contextlib import contextmanager from typing import Generator, Optional diff --git a/arcade/gui/ui_manager.py b/arcade/gui/ui_manager.py index a55d2013aa..6f27c2beaf 100644 --- a/arcade/gui/ui_manager.py +++ b/arcade/gui/ui_manager.py @@ -8,8 +8,6 @@ - TextArea with scroll support """ -from __future__ import annotations - from collections import defaultdict from typing import Iterable, Optional, TypeVar, Union diff --git a/arcade/gui/view.py b/arcade/gui/view.py index 110f62734d..885f4587a1 100644 --- a/arcade/gui/view.py +++ b/arcade/gui/view.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import TypeVar from arcade import View diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index 26a56d4c42..bd4e78e9c3 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -1,4 +1,3 @@ -from __future__ import annotations from abc import ABC from typing import Dict, Iterable, List, NamedTuple, Optional, TYPE_CHECKING, Tuple, TypeVar, Union diff --git a/arcade/gui/widgets/buttons.py b/arcade/gui/widgets/buttons.py index c3588e4284..e4cc6c8f50 100644 --- a/arcade/gui/widgets/buttons.py +++ b/arcade/gui/widgets/buttons.py @@ -1,4 +1,3 @@ -from __future__ import annotations from dataclasses import dataclass from typing import Optional, Union diff --git a/arcade/gui/widgets/dropdown.py b/arcade/gui/widgets/dropdown.py index a162f5b66f..3e663a5617 100644 --- a/arcade/gui/widgets/dropdown.py +++ b/arcade/gui/widgets/dropdown.py @@ -1,4 +1,3 @@ -from __future__ import annotations from copy import deepcopy from typing import Optional, Union diff --git a/arcade/gui/widgets/image.py b/arcade/gui/widgets/image.py index c5e981f825..17222f16db 100644 --- a/arcade/gui/widgets/image.py +++ b/arcade/gui/widgets/image.py @@ -1,4 +1,3 @@ -from __future__ import annotations import math from typing import Union diff --git a/arcade/gui/widgets/text.py b/arcade/gui/widgets/text.py index 16f8e932b5..d8dca25e6f 100644 --- a/arcade/gui/widgets/text.py +++ b/arcade/gui/widgets/text.py @@ -1,4 +1,3 @@ -from __future__ import annotations from typing import Optional diff --git a/arcade/gui/widgets/toggle.py b/arcade/gui/widgets/toggle.py index d854dce105..3eb7e39e12 100644 --- a/arcade/gui/widgets/toggle.py +++ b/arcade/gui/widgets/toggle.py @@ -1,4 +1,3 @@ -from __future__ import annotations from typing import Optional diff --git a/arcade/hitbox/__init__.py b/arcade/hitbox/__init__.py index ab5d304dcf..becf40679d 100644 --- a/arcade/hitbox/__init__.py +++ b/arcade/hitbox/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from PIL.Image import Image from arcade.types import Point2List diff --git a/arcade/hitbox/bounding_box.py b/arcade/hitbox/bounding_box.py index 7f6d99d62e..1550df8379 100644 --- a/arcade/hitbox/bounding_box.py +++ b/arcade/hitbox/bounding_box.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from PIL.Image import Image from arcade.types import Point2List diff --git a/arcade/hitbox/pymunk.py b/arcade/hitbox/pymunk.py index 104c731d0f..91fd5056d6 100644 --- a/arcade/hitbox/pymunk.py +++ b/arcade/hitbox/pymunk.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import pymunk from PIL.Image import Image from pymunk import Vec2d diff --git a/arcade/hitbox/simple.py b/arcade/hitbox/simple.py index c6b7b25d25..718cbaf893 100644 --- a/arcade/hitbox/simple.py +++ b/arcade/hitbox/simple.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from PIL.Image import Image from arcade.types import Point, Point2List diff --git a/arcade/isometric.py b/arcade/isometric.py index 097cb21772..e2166d1214 100644 --- a/arcade/isometric.py +++ b/arcade/isometric.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from arcade.shape_list import ShapeElementList, create_line from arcade.types import RGBA255 diff --git a/arcade/joysticks.py b/arcade/joysticks.py index 40279956b2..826d1690e0 100644 --- a/arcade/joysticks.py +++ b/arcade/joysticks.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import pyglet.input from pyglet.input import Joystick diff --git a/arcade/key/__init__.py b/arcade/key/__init__.py index d0207f6e1f..fb1227c6ef 100644 --- a/arcade/key/__init__.py +++ b/arcade/key/__init__.py @@ -2,7 +2,6 @@ Constants used to signify what keys on the keyboard were pressed. """ -from __future__ import annotations from sys import platform # Key modifiers diff --git a/arcade/management/__init__.py b/arcade/management/__init__.py index 28b8310dd3..ec5c7522f0 100644 --- a/arcade/management/__init__.py +++ b/arcade/management/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path import shutil import sys diff --git a/arcade/math.py b/arcade/math.py index 86a55473d9..bf9d03de60 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import math import random from typing import TypeVar diff --git a/arcade/particles/__init__.py b/arcade/particles/__init__.py index d1121372c5..609ab39535 100644 --- a/arcade/particles/__init__.py +++ b/arcade/particles/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from .particle import ( Particle, EternalParticle, diff --git a/arcade/particles/emitter.py b/arcade/particles/emitter.py index ec6b248301..099831d637 100644 --- a/arcade/particles/emitter.py +++ b/arcade/particles/emitter.py @@ -3,8 +3,6 @@ actually emits them, and manages them over their lifetime """ -from __future__ import annotations - from typing import Callable, cast import arcade diff --git a/arcade/particles/emitter_simple.py b/arcade/particles/emitter_simple.py index b69bbdc41b..e049932b23 100644 --- a/arcade/particles/emitter_simple.py +++ b/arcade/particles/emitter_simple.py @@ -5,8 +5,6 @@ to start using particle systems. """ -from __future__ import annotations - import random from typing import Sequence diff --git a/arcade/particles/particle.py b/arcade/particles/particle.py index b161103e5c..0b0f9ee20d 100644 --- a/arcade/particles/particle.py +++ b/arcade/particles/particle.py @@ -3,8 +3,6 @@ Often used in large quantity to produce visual effects effects """ -from __future__ import annotations - from typing import Literal from arcade.math import clamp, lerp diff --git a/arcade/paths.py b/arcade/paths.py index 439d0ff937..8c9e65c168 100644 --- a/arcade/paths.py +++ b/arcade/paths.py @@ -2,8 +2,6 @@ Classic A-star algorithm for path finding. """ -from __future__ import annotations - import math from arcade import Sprite, SpriteList, check_for_collision_with_list, get_sprites_at_point diff --git a/arcade/perf_graph.py b/arcade/perf_graph.py index 2b34781bc5..1809d31f8f 100644 --- a/arcade/perf_graph.py +++ b/arcade/perf_graph.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import random import pyglet.clock diff --git a/arcade/perf_info.py b/arcade/perf_info.py index efb1b67e32..2559a0547c 100644 --- a/arcade/perf_info.py +++ b/arcade/perf_info.py @@ -2,8 +2,6 @@ Utility functions to keep performance information """ -from __future__ import annotations - import time from collections import deque diff --git a/arcade/physics_engines.py b/arcade/physics_engines.py index 065ce8504f..ba2f69bd44 100644 --- a/arcade/physics_engines.py +++ b/arcade/physics_engines.py @@ -2,8 +2,6 @@ Physics engines for top-down or platformers. """ -from __future__ import annotations - import math from typing import Iterable diff --git a/arcade/pymunk_physics_engine.py b/arcade/pymunk_physics_engine.py index e1a9e856e8..8d47d7453a 100644 --- a/arcade/pymunk_physics_engine.py +++ b/arcade/pymunk_physics_engine.py @@ -2,8 +2,6 @@ Pymunk Physics Engine """ -from __future__ import annotations - import logging import math from typing import Callable diff --git a/arcade/resources/__init__.py b/arcade/resources/__init__.py index f471190530..4397312bc5 100644 --- a/arcade/resources/__init__.py +++ b/arcade/resources/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path from typing import Sequence from arcade.exceptions import warning, ReplacementWarning diff --git a/arcade/scene.py b/arcade/scene.py index f551523b82..d9063b4027 100644 --- a/arcade/scene.py +++ b/arcade/scene.py @@ -10,8 +10,6 @@ * Control sprite list draw order within the group """ -from __future__ import annotations - from typing import Iterable from warnings import warn diff --git a/arcade/screenshot.py b/arcade/screenshot.py index 2a330c5a42..28b7a1b0d5 100644 --- a/arcade/screenshot.py +++ b/arcade/screenshot.py @@ -4,8 +4,6 @@ These functions are flawed because they only read from the screen. """ -from __future__ import annotations - import PIL.Image import PIL.ImageOps diff --git a/arcade/shape_list.py b/arcade/shape_list.py index c1a191b30f..af01cde14b 100644 --- a/arcade/shape_list.py +++ b/arcade/shape_list.py @@ -6,8 +6,6 @@ the graphics card for much faster render times. """ -from __future__ import annotations - import itertools import math from array import array diff --git a/arcade/sound.py b/arcade/sound.py index 6530f4d781..292a6e08ba 100644 --- a/arcade/sound.py +++ b/arcade/sound.py @@ -1,7 +1,5 @@ """Sound Library.""" -from __future__ import annotations - import logging import math import os diff --git a/arcade/sprite/__init__.py b/arcade/sprite/__init__.py index 9a6ad5c9d3..724680a915 100644 --- a/arcade/sprite/__init__.py +++ b/arcade/sprite/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path import PIL.Image diff --git a/arcade/sprite/animated.py b/arcade/sprite/animated.py index fec99c65c4..0a88035f3f 100644 --- a/arcade/sprite/animated.py +++ b/arcade/sprite/animated.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import bisect import logging import math diff --git a/arcade/sprite/enums.py b/arcade/sprite/enums.py index 15c5bbb91d..3239c9af73 100644 --- a/arcade/sprite/enums.py +++ b/arcade/sprite/enums.py @@ -1,5 +1,3 @@ -from __future__ import annotations - FACE_RIGHT = 1 FACE_LEFT = 2 FACE_UP = 3 diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index a8189aff19..e07f5eb5c5 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,5 +1,3 @@ -from __future__ import annotations - class PyMunk: """Object used to hold pymunk info for a sprite.""" diff --git a/arcade/sprite/sprite.py b/arcade/sprite/sprite.py index ece5d3c3fe..761cf86672 100644 --- a/arcade/sprite/sprite.py +++ b/arcade/sprite/sprite.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import math from pathlib import Path from typing import TYPE_CHECKING, Any diff --git a/arcade/sprite_list/__init__.py b/arcade/sprite_list/__init__.py index fa5857699f..465fe90ddf 100644 --- a/arcade/sprite_list/__init__.py +++ b/arcade/sprite_list/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from .sprite_list import SpriteList from .spatial_hash import SpatialHash from .collision import ( diff --git a/arcade/sprite_list/collision.py b/arcade/sprite_list/collision.py index 118e115775..f7955f0d3a 100644 --- a/arcade/sprite_list/collision.py +++ b/arcade/sprite_list/collision.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import struct from typing import ( Iterable, diff --git a/arcade/sprite_list/spatial_hash.py b/arcade/sprite_list/spatial_hash.py index 80c717a76e..53ddb3ffdc 100644 --- a/arcade/sprite_list/spatial_hash.py +++ b/arcade/sprite_list/spatial_hash.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from math import trunc from typing import Generic diff --git a/arcade/text.py b/arcade/text.py index ae03a12170..9ab51b21df 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -2,8 +2,6 @@ Drawing text with pyglet label """ -from __future__ import annotations - from ctypes import c_int, c_ubyte from pathlib import Path from typing import Any, Union diff --git a/arcade/texture/__init__.py b/arcade/texture/__init__.py index 38c4afc1bd..a6a6949f63 100644 --- a/arcade/texture/__init__.py +++ b/arcade/texture/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from .texture import Texture, ImageData from .spritesheet import SpriteSheet from .loading import ( diff --git a/arcade/texture/generate.py b/arcade/texture/generate.py index af98ce7dc3..3d5b2b0ba7 100644 --- a/arcade/texture/generate.py +++ b/arcade/texture/generate.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import PIL.Image import PIL.ImageDraw import PIL.ImageOps diff --git a/arcade/texture/loading.py b/arcade/texture/loading.py index a100929077..6f9f91e128 100644 --- a/arcade/texture/loading.py +++ b/arcade/texture/loading.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path from PIL import Image diff --git a/arcade/texture/manager.py b/arcade/texture/manager.py index b72f76dc57..b45ef01282 100644 --- a/arcade/texture/manager.py +++ b/arcade/texture/manager.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pathlib import Path import PIL.Image diff --git a/arcade/texture/tools.py b/arcade/texture/tools.py index de16349982..8c55fcac58 100644 --- a/arcade/texture/tools.py +++ b/arcade/texture/tools.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from PIL import Image, ImageDraw import arcade diff --git a/arcade/texture/transforms.py b/arcade/texture/transforms.py index 1e8a7de19a..5c7fcf45e7 100644 --- a/arcade/texture/transforms.py +++ b/arcade/texture/transforms.py @@ -6,8 +6,6 @@ transform the texture coordinates and hit box points. """ -from __future__ import annotations - from enum import Enum from arcade.math import rotate_point diff --git a/arcade/texture_atlas/__init__.py b/arcade/texture_atlas/__init__.py index 452f41853d..89bfbf5204 100644 --- a/arcade/texture_atlas/__init__.py +++ b/arcade/texture_atlas/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from .atlas_default import ( DefaultTextureAtlas, AtlasRegion, diff --git a/arcade/texture_atlas/atlas_array.py b/arcade/texture_atlas/atlas_array.py index e9b23ebd6c..5f15eab310 100644 --- a/arcade/texture_atlas/atlas_array.py +++ b/arcade/texture_atlas/atlas_array.py @@ -2,8 +2,6 @@ THIS IS WORK IN PROGRESS. DO NOT USE. """ -from __future__ import annotations - from typing import ( TYPE_CHECKING, Tuple, diff --git a/arcade/texture_atlas/atlas_bindless.py b/arcade/texture_atlas/atlas_bindless.py index 0a3d4ce979..0db4933057 100644 --- a/arcade/texture_atlas/atlas_bindless.py +++ b/arcade/texture_atlas/atlas_bindless.py @@ -2,8 +2,6 @@ THIS IS WORK IN PROGRESS. DO NOT USE. """ -from __future__ import annotations - from typing import TYPE_CHECKING from .base import TextureAtlasBase diff --git a/arcade/texture_atlas/helpers.py b/arcade/texture_atlas/helpers.py deleted file mode 100644 index c6b0fb8dfc..0000000000 --- a/arcade/texture_atlas/helpers.py +++ /dev/null @@ -1,187 +0,0 @@ -# """ -# THIS IS AN EXPERIMENTAL MODULE WITH NO GUARANTEES OF STABILITY OR SUPPORT. -# """ -# from __future__ import annotations - -# import json -# from pathlib import Path -# from time import perf_counter -# from typing import Dict, Tuple, cast - -# import PIL.Image - -# import arcade -# from arcade import cache -# from arcade.texture import ImageData, Texture - -# from .atlas_2d import AtlasRegion, DefaultTextureAtlas - - -# class FakeImage: -# """A fake PIL image""" -# def __init__(self, size): -# self.size = size - -# @property -# def width(self): -# return self.size[0] - -# @property -# def height(self): -# return self.size[1] - - -# def _dump_region_info(region: AtlasRegion): -# return { -# "pos": [region.x, region.y], -# "size": [region.width, region.height], -# "uvs": region.texture_coordinates, -# } - - -# def save_atlas(atlas: DefaultTextureAtlas, directory: Path, name: str, resource_root: Path): -# """ -# Dump the atlas to a file. This includes the atlas image -# and metadata. - -# Args: -# atlas: The atlas to dump -# directory: The directory to dump the atlas to -# name: The name of the atlas -# """ -# # Dump the image -# atlas.save(directory / f"{name}.png", flip=False) - -# meta = { -# 'name': name, -# 'atlas_file': f"{name}.png", -# 'size': atlas.size, -# 'border': atlas.border, -# 'textures': [], -# 'images': [], -# } -# # Images -# images = [] -# for image in atlas._images: -# images.append({ -# "hash": image.hash, -# "region": _dump_region_info(atlas.get_image_region_info(image.hash)), -# }) -# meta['images'] = images - -# # Textures -# textures = [] -# for texture in atlas.textures: -# if texture.file_path is None: -# raise ValueError("Can't save a texture not loaded from a file") - -# textures.append({ -# "hash": texture.image_data.hash, -# "path": texture.file_path.relative_to(resource_root).as_posix(), -# "crop": texture.crop_values, -# "points": texture.hit_box_points, -# "region": _dump_region_info(atlas.get_texture_region_info(texture.atlas_name)), -# "vertex_order": texture._vertex_order, -# }) - -# meta['textures'] = textures - -# # Dump the metadata -# with open(directory / f"{name}.json", 'w') as fd: -# json.dump(meta, fd, indent=2) - - -# def load_atlas( -# meta_file: Path, -# resource_root: Path -# ) -> Tuple[TextureAtlas, Dict[str, float]]: -# """ -# Load a texture atlas from disk. -# """ -# ctx = arcade.get_window().ctx -# perf_data = {} - -# t = perf_counter() -# # Load metadata -# with open(meta_file, 'r') as fd: -# meta = json.load(fd) -# perf_data['load_meta'] = perf_counter() - t - -# t = perf_counter() -# atlas = DefaultTextureAtlas( -# meta['size'], -# border=meta["border"], -# auto_resize=False, -# ) -# perf_data['create_atlas'] = perf_counter() - t - -# # Inject the atlas image -# t = perf_counter() -# atlas._texture = ctx.load_texture(meta['atlas_file'], flip=False) -# atlas._fbo = ctx.framebuffer(color_attachments=[atlas._texture]) -# perf_data['load_texture'] = perf_counter() - t - -# # Recreate images -# t = perf_counter() -# image_map: Dict[str, ImageData] = {} -# for im in meta['images']: -# image_data = ImageData( -# cast(PIL.Image.Image, FakeImage(im['region']['size'])), -# im['hash'], -# ) -# atlas._images.add(image_data) -# image_map[image_data.hash] = image_data -# # cache.image_data_cache.put() -# region = AtlasRegion( -# atlas, -# im['region']['pos'][0], -# im['region']['pos'][1], -# im['region']['size'][0], -# im['region']['size'][1], -# tuple(im['region']['uvs']), # type: ignore -# ) -# atlas._image_regions[image_data.hash] = region -# # Get a slot for the image and write the uv data -# slot = atlas._image_uv_slots_free.popleft() -# atlas._image_uv_slots[image_data.hash] = slot -# for i in range(8): -# atlas._image_uv_data[slot * 8 + i] = region.texture_coordinates[i] - -# perf_data['create_images'] = perf_counter() - t - -# # Recreate textures -# t = perf_counter() -# for tex in meta['textures']: -# texture = Texture( -# image_map[tex['hash']], -# hit_box_points=tex['points'], -# ) -# texture._vertex_order = tuple(tex['vertex_order']) # type: ignore -# texture._update_cache_names() -# atlas._textures[texture.atlas_name] = texture -# # Cache the texture strongly so it doesn't get garbage collected -# cache.texture_cache.put(texture, file_path=resource_root / tex['hash']) -# texture.file_path = resource_root / tex['path'] -# texture.crop_values = tex['crop'] -# region = AtlasRegion( -# atlas, -# tex['region']['pos'][0], -# tex['region']['pos'][1], -# tex['region']['size'][0], -# tex['region']['size'][1], -# tuple(tex['region']['uvs']), # type: ignore -# ) -# atlas._texture_regions[texture.atlas_name] = region -# # Get a slot for the image and write the uv data -# slot = atlas._texture_uv_slots_free.popleft() -# atlas._texture_uv_slots[texture.atlas_name] = slot -# for i in range(8): -# atlas._texture_uv_data[slot * 8 + i] = region.texture_coordinates[i] - -# perf_data['create_textures'] = perf_counter() - t - -# # Write the uv data to vram -# atlas.use_uv_texture() - -# return atlas, perf_data -# return atlas, perf_data diff --git a/arcade/texture_atlas/ref_counters.py b/arcade/texture_atlas/ref_counters.py index f77e432456..6740f8b54f 100644 --- a/arcade/texture_atlas/ref_counters.py +++ b/arcade/texture_atlas/ref_counters.py @@ -8,8 +8,6 @@ simply a texture using the same image and the same vertex order. """ -from __future__ import annotations - from typing import TYPE_CHECKING, Dict if TYPE_CHECKING: diff --git a/arcade/tilemap/__init__.py b/arcade/tilemap/__init__.py index fe296379ea..cd9a07b6bf 100644 --- a/arcade/tilemap/__init__.py +++ b/arcade/tilemap/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from .tilemap import TileMap, load_tilemap __all__ = ["TileMap", "load_tilemap"] diff --git a/arcade/types/__init__.py b/arcade/types/__init__.py index e71eef2e5c..da08112cd0 100644 --- a/arcade/types/__init__.py +++ b/arcade/types/__init__.py @@ -20,8 +20,6 @@ they go in the :py:mod:`arcade.types.color` submodule. """ -from __future__ import annotations - # Don't lint import order since we have conditional compatibility shims # flake8: noqa: E402 import sys diff --git a/arcade/types/numbers.py b/arcade/types/numbers.py index 8a5fbc623f..6ece433e08 100644 --- a/arcade/types/numbers.py +++ b/arcade/types/numbers.py @@ -5,8 +5,6 @@ circular imports or partially initialized modules. """ -from __future__ import annotations - from typing import Union #: 1. Makes pyright happier while also telling readers diff --git a/arcade/types/vector_like.py b/arcade/types/vector_like.py index fe31da458a..782694468c 100644 --- a/arcade/types/vector_like.py +++ b/arcade/types/vector_like.py @@ -7,8 +7,6 @@ """ -from __future__ import annotations - from typing import Sequence, Union from pyglet.math import Vec2, Vec3 diff --git a/arcade/utils.py b/arcade/utils.py index 490be539fb..547820d47e 100644 --- a/arcade/utils.py +++ b/arcade/utils.py @@ -4,8 +4,6 @@ IMPORTANT: These should be standalone and not rely on any Arcade imports """ -from __future__ import annotations - import platform import sys from collections.abc import MutableSequence diff --git a/arcade/version.py b/arcade/version.py index 2105f1e27e..bcf99536fb 100644 --- a/arcade/version.py +++ b/arcade/version.py @@ -26,8 +26,6 @@ """ -from __future__ import annotations - import re import sys from pathlib import Path diff --git a/benchmarks/sprite/sprite_alt.py b/benchmarks/sprite/sprite_alt.py index 066a57d4f2..db09941b4e 100644 --- a/benchmarks/sprite/sprite_alt.py +++ b/benchmarks/sprite/sprite_alt.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from typing import TYPE_CHECKING, Any, Iterable, TypeVar import arcade diff --git a/doc/conf.py b/doc/conf.py index 03f5320b39..82b8bd05d5 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,7 +1,5 @@ #!/usr/bin/env python """Sphinx configuration file""" -from __future__ import annotations - import os from functools import cache import logging diff --git a/make.py b/make.py index 9639db7330..9b90466b5a 100755 --- a/make.py +++ b/make.py @@ -12,8 +12,6 @@ * The output of python make.py --help """ -from __future__ import annotations - import os import subprocess from contextlib import contextmanager diff --git a/pyproject.toml b/pyproject.toml index 0c9d917f0f..3a995d57c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,14 +4,13 @@ description = "Arcade Game Development Library" readme = "README.md" authors = [{ name = "Paul Vincent Craven", email = "paul@cravenfamily.com" }] license = { file = "license.rst" } -requires-python = ">=3.9" +requires-python = ">=3.10" classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", diff --git a/tests/conftest.py b/tests/conftest.py index b053294291..d11069917a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import os from pathlib import Path diff --git a/tests/manual_smoke/sprite_collision_inspector.py b/tests/manual_smoke/sprite_collision_inspector.py index b18ac88f2f..401c317098 100644 --- a/tests/manual_smoke/sprite_collision_inspector.py +++ b/tests/manual_smoke/sprite_collision_inspector.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import builtins from typing import TypeVar, Type, Generic, Any, Callable diff --git a/tests/unit/gui/__init__.py b/tests/unit/gui/__init__.py index d2de0281bd..99f284eaf9 100644 --- a/tests/unit/gui/__init__.py +++ b/tests/unit/gui/__init__.py @@ -1,5 +1,3 @@ -from __future__ import annotations # allow |-type hinting in Python 3.9 - from abc import abstractmethod from contextlib import contextmanager from typing import List diff --git a/tests/unit/rect/test_rect_creation_helpers.py b/tests/unit/rect/test_rect_creation_helpers.py index ab6f9f83b4..928145762d 100644 --- a/tests/unit/rect/test_rect_creation_helpers.py +++ b/tests/unit/rect/test_rect_creation_helpers.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import pytest from arcade.types.rect import LBWH, LRBT, XYWH, XYRR, Rect diff --git a/util/create_resources_listing.py b/util/create_resources_listing.py index 48219f22bf..8213a0cde2 100644 --- a/util/create_resources_listing.py +++ b/util/create_resources_listing.py @@ -5,8 +5,6 @@ """ # fmt: off # ruff: noqa -from __future__ import annotations - import copy import html import re diff --git a/util/doc_helpers/import_resolver.py b/util/doc_helpers/import_resolver.py index d4b88a5dc7..ffb3f2d9c2 100644 --- a/util/doc_helpers/import_resolver.py +++ b/util/doc_helpers/import_resolver.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import ast import dataclasses from pathlib import Path diff --git a/util/doc_helpers/real_filesystem.py b/util/doc_helpers/real_filesystem.py index aa3478776b..69ff96beb3 100644 --- a/util/doc_helpers/real_filesystem.py +++ b/util/doc_helpers/real_filesystem.py @@ -2,8 +2,6 @@ Helpers for dealing with the real-world file system. """ -from __future__ import annotations - import shutil from pathlib import Path from typing import Generator, TypeVar, Hashable, Iterable, Mapping, Sequence, Callable diff --git a/util/doc_helpers/vfs.py b/util/doc_helpers/vfs.py index 3cc3ff2875..c88baafce1 100644 --- a/util/doc_helpers/vfs.py +++ b/util/doc_helpers/vfs.py @@ -27,8 +27,6 @@ by reading each file before write and aborting if its contents would be unchanged. """ -from __future__ import annotations -import os from contextlib import suppress, contextmanager from io import StringIO from pathlib import Path diff --git a/util/update_quick_index.py b/util/update_quick_index.py index 8f4b41b8d6..c9a0731d8a 100644 --- a/util/update_quick_index.py +++ b/util/update_quick_index.py @@ -11,8 +11,6 @@ a # --- so you can skip between them in diffs or your favorite editor via hotkeys. """ -from __future__ import annotations - import re import sys from collections.abc import Mapping From 0ab6fdfbcd29b32c60561a0b4e6d08e6e14d2c6c Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Fri, 28 Mar 2025 16:26:34 +0100 Subject: [PATCH 2/5] update to Python 3.10 code --- arcade/examples/gui/4_with_camera.py | 7 +- arcade/future/input/input_manager_example.py | 4 +- arcade/future/input/input_mapping.py | 1 + arcade/future/input/manager.py | 2 + arcade/future/sub_clock.py | 6 +- arcade/gl/exceptions.py | 1 - arcade/gui/constructs.py | 6 +- arcade/gui/experimental/password_input.py | 4 +- arcade/gui/experimental/restricted_input.py | 4 +- arcade/gui/experimental/scroll_area.py | 6 +- arcade/gui/experimental/typed_text_input.py | 4 +- arcade/gui/mixins.py | 6 +- arcade/gui/surface.py | 4 +- arcade/gui/ui_manager.py | 6 +- arcade/gui/widgets/__init__.py | 19 +- arcade/gui/widgets/buttons.py | 9 +- arcade/gui/widgets/dropdown.py | 7 +- arcade/gui/widgets/image.py | 1 - arcade/gui/widgets/layout.py | 10 +- arcade/gui/widgets/slider.py | 4 +- arcade/gui/widgets/text.py | 27 ++- arcade/gui/widgets/toggle.py | 7 +- arcade/particles/emitter.py | 1 + arcade/sprite/mixins.py | 1 - doc/tutorials/card_game/solitaire_11.py | 61 ++++--- .../pymunk_demo_platformer.py | 16 +- .../pymunk_demo_platformer_02.py | 2 - .../pymunk_demo_platformer_03.py | 27 +-- .../pymunk_demo_platformer_04.py | 33 ++-- .../pymunk_demo_platformer_05.py | 71 ++++---- .../pymunk_demo_platformer_06.py | 73 ++++---- .../pymunk_demo_platformer_07.py | 12 +- .../pymunk_demo_platformer_08.py | 76 ++++---- .../pymunk_demo_platformer_09.py | 13 +- .../pymunk_demo_platformer_10.py | 12 +- .../pymunk_demo_platformer_11.py | 15 +- .../pymunk_demo_platformer_12.py | 169 ++++++++++-------- tests/unit/color/test_module_color.py | 6 +- tests/unit/color/test_module_csscolor.py | 4 +- 39 files changed, 388 insertions(+), 349 deletions(-) diff --git a/arcade/examples/gui/4_with_camera.py b/arcade/examples/gui/4_with_camera.py index ab4245ba64..08c277b099 100644 --- a/arcade/examples/gui/4_with_camera.py +++ b/arcade/examples/gui/4_with_camera.py @@ -12,7 +12,6 @@ import math import random -from typing import Optional import arcade from arcade.gui import UIAnchorLayout, UIBoxLayout, UIFlatButton, UILabel, UIOnClickEvent, UIView @@ -162,7 +161,7 @@ def on_draw_before_ui(self): self.sprites.draw() self.coins.draw() - def on_update(self, delta_time: float) -> Optional[bool]: + def on_update(self, delta_time: float) -> bool | None: if self._total_time > self._game_duration: # ad new UI label to show the end of the game game_over_text = self.ui.add( @@ -242,7 +241,7 @@ def on_update(self, delta_time: float) -> Optional[bool]: return False - def on_key_press(self, symbol: int, modifiers: int) -> Optional[bool]: + def on_key_press(self, symbol: int, modifiers: int) -> bool | None: self.keys.add(symbol) if symbol == arcade.key.ESCAPE: @@ -252,7 +251,7 @@ def on_key_press(self, symbol: int, modifiers: int) -> Optional[bool]: return False - def on_key_release(self, symbol: int, modifiers: int) -> Optional[bool]: + def on_key_release(self, symbol: int, modifiers: int) -> bool | None: if symbol in self.keys: self.keys.remove(symbol) return False diff --git a/arcade/future/input/input_manager_example.py b/arcade/future/input/input_manager_example.py index b71f5e5337..0fce91380c 100644 --- a/arcade/future/input/input_manager_example.py +++ b/arcade/future/input/input_manager_example.py @@ -1,6 +1,6 @@ # type: ignore import random -from typing import Optional, Sequence +from typing import Sequence import pyglet from pyglet.input import Controller @@ -28,7 +28,7 @@ def __init__( texture, walls: arcade.SpriteList, input_manager_template: InputManager, - controller: Optional[pyglet.input.Controller] = None, + controller: pyglet.input.Controller | None = None, center_x: float = 0.0, center_y: float = 0.0, x_max_speed: float = 300.0, diff --git a/arcade/future/input/input_mapping.py b/arcade/future/input/input_mapping.py index 19e21b937b..a6acd962d5 100644 --- a/arcade/future/input/input_mapping.py +++ b/arcade/future/input/input_mapping.py @@ -1,4 +1,5 @@ # type: ignore +from __future__ import annotations from arcade.future.input import inputs from arcade.future.input.raw_dicts import RawAction, RawActionMapping, RawAxis, RawAxisMapping diff --git a/arcade/future/input/manager.py b/arcade/future/input/manager.py index ed4fe907a4..104a6635d9 100644 --- a/arcade/future/input/manager.py +++ b/arcade/future/input/manager.py @@ -1,4 +1,6 @@ # type: ignore +from __future__ import annotations + from enum import Enum from typing import Any, Callable, TypeVar diff --git a/arcade/future/sub_clock.py b/arcade/future/sub_clock.py index 11c8df7624..339e324db0 100644 --- a/arcade/future/sub_clock.py +++ b/arcade/future/sub_clock.py @@ -1,9 +1,11 @@ -from typing import Optional, Union +from __future__ import annotations + +from typing import Union from arcade.clock import GLOBAL_CLOCK, Clock -def boot_strap_clock(clock: Optional[Clock] = None) -> Clock: +def boot_strap_clock(clock: Clock | None = None) -> Clock: """ Because the sub_clock is not a fully featured part of Arcade we have to manipulate the clocks before the can be used with sub_clocks. diff --git a/arcade/gl/exceptions.py b/arcade/gl/exceptions.py index ad9d20ef14..0f6c849272 100644 --- a/arcade/gl/exceptions.py +++ b/arcade/gl/exceptions.py @@ -1,4 +1,3 @@ - class ShaderException(Exception): """Exception class for shader-specific problems.""" diff --git a/arcade/gui/constructs.py b/arcade/gui/constructs.py index 88ea1767a2..de73d774f5 100644 --- a/arcade/gui/constructs.py +++ b/arcade/gui/constructs.py @@ -1,6 +1,6 @@ """Constructs, are prepared widget combinations, you can use for common use-cases""" -from typing import Any, Optional +from typing import Any import arcade from arcade import uicolor @@ -138,8 +138,8 @@ def __init__( vertical: bool = False, align: str = "center", size_hint: Any = (0, 0), - size_hint_min: Optional[Any] = None, - size_hint_max: Optional[Any] = None, + size_hint_min: Any | None = None, + size_hint_max: Any | None = None, space_between: int = 10, button_factory: type = UIFlatButton, **kwargs, diff --git a/arcade/gui/experimental/password_input.py b/arcade/gui/experimental/password_input.py index afed0f6f2e..a9b9ecc01c 100644 --- a/arcade/gui/experimental/password_input.py +++ b/arcade/gui/experimental/password_input.py @@ -1,5 +1,3 @@ -from typing import Optional - from arcade.gui import Surface, UIEvent, UIInputText, UITextInputEvent @@ -11,7 +9,7 @@ class UIPasswordInput(UIInputText): """ - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """Remove new lines from the input, which are not allowed in passwords.""" if isinstance(event, UITextInputEvent): event.text = event.text.replace("\n", "").replace("\r", "") diff --git a/arcade/gui/experimental/restricted_input.py b/arcade/gui/experimental/restricted_input.py index 1d7a41494c..1d9e3ea5d0 100644 --- a/arcade/gui/experimental/restricted_input.py +++ b/arcade/gui/experimental/restricted_input.py @@ -3,8 +3,6 @@ If the implementation is successful, the feature will be merged into the existing UIInputText class. """ -from typing import Optional - from arcade.gui import UIEvent, UIInputText @@ -32,7 +30,7 @@ def text(self, text: str): # we can not call super().text = text here: https://bugs.python.org/issue14965 UIInputText.text.__set__(self, text) # type: ignore - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: # check if text changed during event handling, # if so we need to validate the new text old_text = self.text diff --git a/arcade/gui/experimental/scroll_area.py b/arcade/gui/experimental/scroll_area.py index 4722c01c96..cc1bc55352 100644 --- a/arcade/gui/experimental/scroll_area.py +++ b/arcade/gui/experimental/scroll_area.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Iterable, Optional +from typing import Iterable from pyglet.event import EVENT_UNHANDLED @@ -52,7 +52,7 @@ def __init__(self, scroll_area: UIScrollArea, vertical: bool = True): bind(scroll_area, "content_height", self.trigger_full_render) bind(scroll_area, "content_width", self.trigger_full_render) - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: # check if we are scrollable if not self._scrollable(): return EVENT_UNHANDLED @@ -341,7 +341,7 @@ def _get_scroll_offset(self): return self.scroll_x, -normal_pos_y - self.scroll_y - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """Handle scrolling of the widget.""" if isinstance(event, UIMouseDragEvent) and not self.rect.point_in_rect(event.pos): return EVENT_UNHANDLED diff --git a/arcade/gui/experimental/typed_text_input.py b/arcade/gui/experimental/typed_text_input.py index ed2fff5db6..348f14b395 100644 --- a/arcade/gui/experimental/typed_text_input.py +++ b/arcade/gui/experimental/typed_text_input.py @@ -1,4 +1,4 @@ -from typing import Callable, Generic, Optional, Type, TypeVar, cast +from typing import Callable, Generic, Type, TypeVar, cast import arcade from arcade.color import BLACK, RED, WHITE @@ -146,7 +146,7 @@ def _checked_parse(self, text: str): if self.emit_parse_exceptions: raise e - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: # print(f"In {type_name(event)}") if isinstance(event, UITextInputEvent) and self._active: text = event.text.replace("\r", "").replace("\r", "") diff --git a/arcade/gui/mixins.py b/arcade/gui/mixins.py index 8044cdebdd..e902407a02 100644 --- a/arcade/gui/mixins.py +++ b/arcade/gui/mixins.py @@ -1,5 +1,3 @@ -from typing import Optional - from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED from typing_extensions import override @@ -37,7 +35,7 @@ def do_layout(self): self.rect = self.rect.align_top(rect.top).align_left(rect.left) @override - def on_event(self, event) -> Optional[bool]: + def on_event(self, event) -> bool | None: """Handle dragging of the widget.""" if isinstance(event, UIMousePressEvent): if event.button == arcade.MOUSE_BUTTON_LEFT and self.rect.point_in_rect(event.pos): @@ -67,7 +65,7 @@ class UIMouseFilterMixin(UIWidget): """ @override - def on_event(self, event) -> Optional[bool]: + def on_event(self, event) -> bool | None: """Catch all mouse events, that are inside this widget.""" if super().on_event(event): return EVENT_HANDLED diff --git a/arcade/gui/surface.py b/arcade/gui/surface.py index 370d1c2090..2376ec7bcf 100644 --- a/arcade/gui/surface.py +++ b/arcade/gui/surface.py @@ -1,5 +1,5 @@ from contextlib import contextmanager -from typing import Generator, Optional +from typing import Generator from PIL import Image from typing_extensions import Self @@ -217,7 +217,7 @@ def limit(self, rect: Rect | None = None): def draw( self, - area: Optional[Rect] = None, + area: Rect | None = None, ) -> None: """Draws the contents of the surface. diff --git a/arcade/gui/ui_manager.py b/arcade/gui/ui_manager.py index 6f27c2beaf..ffa4c055b0 100644 --- a/arcade/gui/ui_manager.py +++ b/arcade/gui/ui_manager.py @@ -9,7 +9,7 @@ """ from collections import defaultdict -from typing import Iterable, Optional, TypeVar, Union +from typing import Iterable, TypeVar, Union from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED, EventDispatcher from typing_extensions import TypeGuard @@ -93,7 +93,7 @@ def on_draw(): DEFAULT_LAYER = 0 OVERLAY_LAYER = 10 - def __init__(self, window: Optional[arcade.Window] = None): + def __init__(self, window: arcade.Window | None = None): super().__init__() self.window = window or arcade.get_window() @@ -145,7 +145,7 @@ def remove(self, child: UIWidget): self.trigger_render() def walk_widgets( - self, *, root: Optional[UIWidget] = None, layer=DEFAULT_LAYER + self, *, root: UIWidget | None = None, layer=DEFAULT_LAYER ) -> Iterable[UIWidget]: """Walks through widget tree, in reverse draw order (most top drawn widget first) diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index bd4e78e9c3..d03b8382e1 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -1,4 +1,3 @@ - from abc import ABC from typing import Dict, Iterable, List, NamedTuple, Optional, TYPE_CHECKING, Tuple, TypeVar, Union @@ -94,7 +93,7 @@ def __init__( ): self._requires_render = True self.rect = LBWH(x, y, width, height) - self.parent: Optional[Union[UIManager, UIWidget]] = None + self.parent: UIManager | UIWidget | None = None # Size hints are properties that can be used by layouts self.size_hint = size_hint @@ -177,7 +176,7 @@ def on_update(self, dt): """Custom logic which will be triggered.""" pass - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """Passes :class:`UIEvent` s through the widget tree.""" # UpdateEvents are past to the first invisible widget if isinstance(event, UIOnUpdateEvent): @@ -418,11 +417,11 @@ def with_border(self, *, width=2, color: Color | None = arcade.color.GRAY) -> Se def with_padding( self, *, - top: Optional[int] = None, - right: Optional[int] = None, - bottom: Optional[int] = None, - left: Optional[int] = None, - all: Optional[int] = None, + top: int | None = None, + right: int | None = None, + bottom: int | None = None, + left: int | None = None, + all: int | None = None, ) -> Self: """Changes the padding to the given values if set. Returns itself @@ -590,7 +589,7 @@ def __init__( bind(self, "hovered", self.trigger_render) bind(self, "disabled", self.trigger_render) - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """Handles mouse events and triggers on_click event if the widget is clicked. This also sets the hovered and pressed state of the widget. @@ -720,7 +719,7 @@ def __init__( y=0, width=100, height=100, - sprite: Optional[Sprite] = None, + sprite: Sprite | None = None, size_hint=None, size_hint_min=None, size_hint_max=None, diff --git a/arcade/gui/widgets/buttons.py b/arcade/gui/widgets/buttons.py index e4cc6c8f50..22ffa4db2f 100644 --- a/arcade/gui/widgets/buttons.py +++ b/arcade/gui/widgets/buttons.py @@ -1,4 +1,3 @@ - from dataclasses import dataclass from typing import Optional, Union @@ -79,15 +78,15 @@ def __init__( *, x: float = 0, y: float = 0, - width: Optional[float] = None, - height: Optional[float] = None, + width: float | None = None, + height: float | None = None, texture: Union[None, Texture, NinePatchTexture] = None, texture_hovered: Union[None, Texture, NinePatchTexture] = None, texture_pressed: Union[None, Texture, NinePatchTexture] = None, texture_disabled: Union[None, Texture, NinePatchTexture] = None, text: str = "", multiline: bool = False, - scale: Optional[float] = None, + scale: float | None = None, style: Optional[dict[str, UIStyleBase]] = None, size_hint=None, size_hint_min=None, @@ -225,7 +224,7 @@ class UIFlatButtonStyle(UIStyleBase): font_name: FontNameOrNames = ("Kenney Future", "arial", "calibri") font_color: RGBA255 = color.WHITE bg: RGBA255 = uicolor.DARK_BLUE_MIDNIGHT_BLUE - border: Optional[RGBA255] = None + border: RGBA255 | None = None border_width: int = 0 diff --git a/arcade/gui/widgets/dropdown.py b/arcade/gui/widgets/dropdown.py index 3e663a5617..a7aa6968e9 100644 --- a/arcade/gui/widgets/dropdown.py +++ b/arcade/gui/widgets/dropdown.py @@ -1,4 +1,3 @@ - from copy import deepcopy from typing import Optional, Union @@ -110,7 +109,7 @@ def __init__( y: float = 0, width: float = 150, height: float = 30, - default: Optional[str] = None, + default: str | None = None, options: Optional[list[Union[str, None]]] = None, primary_style=None, dropdown_style=None, @@ -151,12 +150,12 @@ def __init__( self.register_event_type("on_change") @property - def value(self) -> Optional[str]: + def value(self) -> str | None: """Current selected option.""" return self._value @value.setter - def value(self, value: Optional[str]): + def value(self, value: str | None): """Change the current selected option to a new option.""" old_value = self._value self._value = value diff --git a/arcade/gui/widgets/image.py b/arcade/gui/widgets/image.py index 17222f16db..b4b4e90eab 100644 --- a/arcade/gui/widgets/image.py +++ b/arcade/gui/widgets/image.py @@ -1,4 +1,3 @@ - import math from typing import Union diff --git a/arcade/gui/widgets/layout.py b/arcade/gui/widgets/layout.py index 61cdfcd3a1..a3d7205f32 100644 --- a/arcade/gui/widgets/layout.py +++ b/arcade/gui/widgets/layout.py @@ -2,7 +2,7 @@ import warnings from dataclasses import dataclass -from typing import Dict, Iterable, List, Optional, Tuple, TypeVar +from typing import Dict, Iterable, List, Tuple, TypeVar from typing_extensions import Literal, override @@ -103,9 +103,9 @@ def add( self, child: W, *, - anchor_x: Optional[str] = None, + anchor_x: str | None = None, align_x: float = 0, - anchor_y: Optional[str] = None, + anchor_y: str | None = None, align_y: float = 0, **kwargs, ) -> W: @@ -140,9 +140,9 @@ def add( def _place_child( self, child: UIWidget, - anchor_x: Optional[str] = None, + anchor_x: str | None = None, align_x: float = 0, - anchor_y: Optional[str] = None, + anchor_y: str | None = None, align_y: float = 0, ): anchor_x = anchor_x or self.default_anchor_x diff --git a/arcade/gui/widgets/slider.py b/arcade/gui/widgets/slider.py index d040885944..70878e913b 100644 --- a/arcade/gui/widgets/slider.py +++ b/arcade/gui/widgets/slider.py @@ -3,7 +3,7 @@ import warnings from abc import ABCMeta, abstractmethod from dataclasses import dataclass -from typing import Mapping, Optional, Union +from typing import Mapping, Union from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED from typing_extensions import override @@ -165,7 +165,7 @@ def _render_thumb(self, surface: Surface): pass @override - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """ Args: event: Event to handle. diff --git a/arcade/gui/widgets/text.py b/arcade/gui/widgets/text.py index d8dca25e6f..cfa37a460a 100644 --- a/arcade/gui/widgets/text.py +++ b/arcade/gui/widgets/text.py @@ -1,6 +1,3 @@ - -from typing import Optional - import pyglet from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED from pyglet.text.caret import Caret @@ -81,8 +78,8 @@ def __init__( *, x: float = 0, y: float = 0, - width: Optional[float] = None, - height: Optional[float] = None, + width: float | None = None, + height: float | None = None, font_name=("calibri", "arial"), font_size: float = 12, text_color: RGBOrA255 = arcade.color.WHITE, @@ -247,11 +244,11 @@ def _update_size_hint_min(self): def update_font( self, - font_name: Optional[FontNameOrNames] = None, - font_size: Optional[float] = None, - font_color: Optional[Color] = None, - bold: Optional[bool | str] = None, - italic: Optional[bool] = None, + font_name: FontNameOrNames | None = None, + font_size: float | None = None, + font_color: Color | None = None, + bold: bool | str | None = None, + italic: bool | None = None, ): """Update font of the label. @@ -346,9 +343,9 @@ def __init__(self, *, text: str, multiline: bool = False, **kwargs): def place_text( self, - anchor_x: Optional[str] = None, + anchor_x: str | None = None, align_x: float = 0, - anchor_y: Optional[str] = None, + anchor_y: str | None = None, align_y: float = 0, **kwargs, ) -> UILabel: @@ -523,7 +520,7 @@ def on_update(self, dt): self.trigger_full_render() @override - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """Handle events for the text input field. Text input is only active when the user clicks on the input field.""" @@ -689,7 +686,7 @@ def __init__( italic=False, text_color: RGBA255 = arcade.color.WHITE, multiline: bool = True, - scroll_speed: Optional[float] = None, + scroll_speed: float | None = None, size_hint=None, size_hint_min=None, size_hint_max=None, @@ -780,7 +777,7 @@ def do_render(self, surface: Surface): self.layout.draw() @override - def on_event(self, event: UIEvent) -> Optional[bool]: + def on_event(self, event: UIEvent) -> bool | None: """Handle scrolling of the widget.""" if isinstance(event, UIMouseScrollEvent): if self.rect.point_in_rect(event.pos): diff --git a/arcade/gui/widgets/toggle.py b/arcade/gui/widgets/toggle.py index 3eb7e39e12..5e1786efe2 100644 --- a/arcade/gui/widgets/toggle.py +++ b/arcade/gui/widgets/toggle.py @@ -1,6 +1,3 @@ - -from typing import Optional - from PIL import ImageEnhance from typing_extensions import override @@ -41,8 +38,8 @@ def __init__( y: float = 0, width: float = 100, height: float = 50, - on_texture: Optional[Texture] = None, - off_texture: Optional[Texture] = None, + on_texture: Texture | None = None, + off_texture: Texture | None = None, value=False, size_hint=None, size_hint_min=None, diff --git a/arcade/particles/emitter.py b/arcade/particles/emitter.py index 099831d637..f6b8a115fc 100644 --- a/arcade/particles/emitter.py +++ b/arcade/particles/emitter.py @@ -2,6 +2,7 @@ Emitter - Invisible object that determines when Particles are emitted, actually emits them, and manages them over their lifetime """ +from __future__ import annotations from typing import Callable, cast diff --git a/arcade/sprite/mixins.py b/arcade/sprite/mixins.py index e07f5eb5c5..4c0ca18af6 100644 --- a/arcade/sprite/mixins.py +++ b/arcade/sprite/mixins.py @@ -1,4 +1,3 @@ - class PyMunk: """Object used to hold pymunk info for a sprite.""" diff --git a/doc/tutorials/card_game/solitaire_11.py b/doc/tutorials/card_game/solitaire_11.py index e7cdaa9d49..1322983419 100644 --- a/doc/tutorials/card_game/solitaire_11.py +++ b/doc/tutorials/card_game/solitaire_11.py @@ -1,9 +1,9 @@ """ Solitaire clone. """ -from typing import Optional import random + import arcade # Screen title and size @@ -71,10 +71,10 @@ class Card(arcade.Sprite): - """ Card sprite """ + """Card sprite""" def __init__(self, suit, value, scale=1): - """ Card constructor """ + """Card constructor""" # Attributes for suit and value self.suit = suit @@ -86,29 +86,29 @@ def __init__(self, suit, value, scale=1): super().__init__(FACE_DOWN_IMAGE, scale, hit_box_algorithm="None") def face_down(self): - """ Turn card face-down """ + """Turn card face-down""" self.texture = arcade.load_texture(FACE_DOWN_IMAGE) self.is_face_up = False def face_up(self): - """ Turn card face-up """ + """Turn card face-up""" self.texture = arcade.load_texture(self.image_file_name) self.is_face_up = True @property def is_face_down(self): - """ Is this card face down? """ + """Is this card face down?""" return not self.is_face_up class MyGame(arcade.Window): - """ Main application class. """ + """Main application class.""" def __init__(self): super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Sprite list with all the cards, no matter what pile they are in. - self.card_list: Optional[arcade.SpriteList] = None + self.card_list: arcade.SpriteList | None = None self.background_color = arcade.color.AMAZON @@ -126,7 +126,7 @@ def __init__(self): self.piles = None def setup(self): - """ Set up the game here. Call this function to restart the game. """ + """Set up the game here. Call this function to restart the game.""" # List of cards we are dragging with the mouse self.held_cards = [] @@ -204,7 +204,7 @@ def setup(self): self.piles[i][-1].face_up() def on_draw(self): - """ Render the screen. """ + """Render the screen.""" # Clear the screen self.clear() @@ -215,27 +215,26 @@ def on_draw(self): self.card_list.draw() def pull_to_top(self, card: arcade.Sprite): - """ Pull card to top of rendering order (last to render, looks on-top) """ + """Pull card to top of rendering order (last to render, looks on-top)""" # Remove, and append to the end self.card_list.remove(card) self.card_list.append(card) def on_key_press(self, symbol: int, modifiers: int): - """ User presses key """ + """User presses key""" if symbol == arcade.key.R: # Restart self.setup() def on_mouse_press(self, x, y, button, key_modifiers): - """ Called when the user presses a mouse button. """ + """Called when the user presses a mouse button.""" # Get list of cards we've clicked on cards = arcade.get_sprites_at_point((x, y), self.card_list) # Have we clicked on a card? if len(cards) > 0: - # Might be a stack of cards, get the top one primary_card = cards[-1] assert isinstance(primary_card, Card) @@ -283,7 +282,6 @@ def on_mouse_press(self, x, y, button, key_modifiers): self.pull_to_top(card) else: - # Click on a mat instead of a card? mats = arcade.get_sprites_at_point((x, y), self.pile_mat_list) @@ -292,7 +290,10 @@ def on_mouse_press(self, x, y, button, key_modifiers): mat_index = self.pile_mat_list.index(mat) # Is it our turned over flip mat? and no cards on it? - if mat_index == BOTTOM_FACE_DOWN_PILE and len(self.piles[BOTTOM_FACE_DOWN_PILE]) == 0: + if ( + mat_index == BOTTOM_FACE_DOWN_PILE + and len(self.piles[BOTTOM_FACE_DOWN_PILE]) == 0 + ): # Flip the deck back over so we can restart temp_list = self.piles[BOTTOM_FACE_UP_PILE].copy() for card in reversed(temp_list): @@ -302,26 +303,25 @@ def on_mouse_press(self, x, y, button, key_modifiers): card.position = self.pile_mat_list[BOTTOM_FACE_DOWN_PILE].position def remove_card_from_pile(self, card): - """ Remove card from whatever pile it was in. """ + """Remove card from whatever pile it was in.""" for pile in self.piles: if card in pile: pile.remove(card) break def get_pile_for_card(self, card): - """ What pile is this card in? """ + """What pile is this card in?""" for index, pile in enumerate(self.piles): if card in pile: return index def move_card_to_new_pile(self, card, pile_index): - """ Move the card to a new pile """ + """Move the card to a new pile""" self.remove_card_from_pile(card) self.piles[pile_index].append(card) - def on_mouse_release(self, x: float, y: float, button: int, - modifiers: int): - """ Called when the user presses a mouse button. """ + def on_mouse_release(self, x: float, y: float, button: int, modifiers: int): + """Called when the user presses a mouse button.""" # If we don't have any cards, who cares if len(self.held_cards) == 0: @@ -333,7 +333,6 @@ def on_mouse_release(self, x: float, y: float, button: int, # See if we are in contact with the closest pile if arcade.check_for_collision(self.held_cards[0], pile): - # What pile is it? pile_index = self.pile_mat_list.index(pile) @@ -349,14 +348,18 @@ def on_mouse_release(self, x: float, y: float, button: int, # Move cards to proper position top_card = self.piles[pile_index][-1] for i, dropped_card in enumerate(self.held_cards): - dropped_card.position = top_card.center_x, \ - top_card.center_y - CARD_VERTICAL_OFFSET * (i + 1) + dropped_card.position = ( + top_card.center_x, + top_card.center_y - CARD_VERTICAL_OFFSET * (i + 1), + ) else: # Are there no cards in the middle play pile? for i, dropped_card in enumerate(self.held_cards): # Move cards to proper position - dropped_card.position = pile.center_x, \ - pile.center_y - CARD_VERTICAL_OFFSET * i + dropped_card.position = ( + pile.center_x, + pile.center_y - CARD_VERTICAL_OFFSET * i, + ) for card in self.held_cards: # Cards are in the right position, but we need to move them to the right list @@ -385,7 +388,7 @@ def on_mouse_release(self, x: float, y: float, button: int, self.held_cards = [] def on_mouse_motion(self, x: float, y: float, dx: float, dy: float): - """ User moves mouse """ + """User moves mouse""" # If we are holding cards, move them with the mouse for card in self.held_cards: @@ -394,7 +397,7 @@ def on_mouse_motion(self, x: float, y: float, dx: float, dy: float): def main(): - """ Main function """ + """Main function""" window = MyGame() window.setup() arcade.run() diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer.py index f316acd685..322beaf907 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer.py @@ -3,12 +3,12 @@ Platformer """ +import logging import math + import arcade -from typing import Optional from arcade.pymunk_physics_engine import PymunkPhysicsEngine -import logging LOG = logging.getLogger(__name__) SCREEN_TITLE = "PyMunk Top-Down" @@ -167,13 +167,13 @@ def __init__(self, width, height, title): super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[arcade.Sprite] = None + self.player_sprite: arcade.Sprite|None= None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList|None= None + self.wall_list: arcade.SpriteList|None= None + self.bullet_list: arcade.SpriteList|None= None + self.item_list: arcade.SpriteList|None= None # Track the current state of what key is pressed self.left_pressed: bool = False @@ -182,7 +182,7 @@ def __init__(self, width, height, title): self.down_pressed: bool = False # The PyMunk physics engine! - self.physics_engine: Optional[PymunkPhysicsEngine] = None + self.physics_engine: PymunkPhysicsEngine|None= None # Set background color self.background_color = arcade.color.AMAZON diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_02.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_02.py index c301cb68c1..2f4d96fcd5 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_02.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_02.py @@ -1,8 +1,6 @@ """ Example of Pymunk Physics Engine Platformer """ -import math -from typing import Optional import arcade SCREEN_TITLE = "PyMunk Platformer" diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_03.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_03.py index 5a5e5e0537..fedf84a346 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_03.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_03.py @@ -1,6 +1,7 @@ """ Example of Pymunk Physics Engine Platformer """ + import math from typing import Optional import arcade @@ -27,22 +28,22 @@ class GameWindow(arcade.Window): - """ Main Window """ + """Main Window""" def __init__(self, width, height, title): - """ Create the variables """ + """Create the variables""" # Init the parent class super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[arcade.Sprite] = None + self.player_sprite: arcade.Sprite | None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList | None = None + self.wall_list: arcade.SpriteList | None = None + self.bullet_list: arcade.SpriteList | None = None + self.item_list: arcade.SpriteList | None = None # Track the current state of what key is pressed self.left_pressed: bool = False @@ -52,28 +53,28 @@ def __init__(self, width, height, title): self.background_color = arcade.color.AMAZON def setup(self): - """ Set up everything with the game """ + """Set up everything with the game""" pass def on_key_press(self, key, modifiers): - """Called whenever a key is pressed. """ + """Called whenever a key is pressed.""" pass def on_key_release(self, key, modifiers): - """Called when the user releases a key. """ + """Called when the user releases a key.""" pass def on_update(self, delta_time): - """ Movement and game logic """ + """Movement and game logic""" pass def on_draw(self): - """ Draw everything """ + """Draw everything""" self.clear() def main(): - """ Main function """ + """Main function""" window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run() diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_04.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_04.py index 803fd6fd5e..f5563d35a0 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_04.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_04.py @@ -1,6 +1,7 @@ """ Example of Pymunk Physics Engine Platformer """ + import math from typing import Optional import arcade @@ -27,22 +28,22 @@ class GameWindow(arcade.Window): - """ Main Window """ + """Main Window""" def __init__(self, width, height, title): - """ Create the variables """ + """Create the variables""" # Init the parent class super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[arcade.Sprite] = None + self.player_sprite: arcade.Sprite | None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList | None = None + self.wall_list: arcade.SpriteList | None = None + self.bullet_list: arcade.SpriteList | None = None + self.item_list: arcade.SpriteList | None = None # Track the current state of what key is pressed self.left_pressed: bool = False @@ -52,7 +53,7 @@ def __init__(self, width, height, title): self.background_color = arcade.color.AMAZON def setup(self): - """ Set up everything with the game """ + """Set up everything with the game""" # Create the sprite lists self.player_list = arcade.SpriteList() @@ -69,8 +70,10 @@ def setup(self): self.item_list = tile_map.sprite_lists["Dynamic Items"] # Create player sprite - self.player_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", - SPRITE_SCALING_PLAYER) + self.player_sprite = arcade.Sprite( + ":resources:images/animated_characters/female_person/femalePerson_idle.png", + SPRITE_SCALING_PLAYER, + ) # Set player location grid_x = 1 grid_y = 1 @@ -80,19 +83,19 @@ def setup(self): self.player_list.append(self.player_sprite) def on_key_press(self, key, modifiers): - """Called whenever a key is pressed. """ + """Called whenever a key is pressed.""" pass def on_key_release(self, key, modifiers): - """Called when the user releases a key. """ + """Called when the user releases a key.""" pass def on_update(self, delta_time): - """ Movement and game logic """ + """Movement and game logic""" pass def on_draw(self): - """ Draw everything """ + """Draw everything""" self.clear() self.wall_list.draw() self.bullet_list.draw() @@ -101,7 +104,7 @@ def on_draw(self): def main(): - """ Main function """ + """Main function""" window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run() diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_05.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_05.py index d89341a725..2f49f98cdb 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_05.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_05.py @@ -1,6 +1,7 @@ """ Example of Pymunk Physics Engine Platformer """ + from typing import Optional import arcade @@ -47,35 +48,35 @@ class GameWindow(arcade.Window): - """ Main Window """ + """Main Window""" def __init__(self, width, height, title): - """ Create the variables """ + """Create the variables""" # Init the parent class super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[arcade.Sprite] = None + self.player_sprite: arcade.Sprite | None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList | None = None + self.wall_list: arcade.SpriteList | None = None + self.bullet_list: arcade.SpriteList | None = None + self.item_list: arcade.SpriteList | None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON def setup(self): - """ Set up everything with the game """ + """Set up everything with the game""" # Create the sprite lists self.player_list = arcade.SpriteList() @@ -92,8 +93,10 @@ def setup(self): self.item_list = tile_map.sprite_lists["Dynamic Items"] # Create player sprite - self.player_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", - SPRITE_SCALING_PLAYER) + self.player_sprite = arcade.Sprite( + ":resources:images/animated_characters/female_person/femalePerson_idle.png", + SPRITE_SCALING_PLAYER, + ) # Set player location grid_x = 1 grid_y = 1 @@ -116,8 +119,7 @@ def setup(self): gravity = (0, -GRAVITY) # Create the physics engine - self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, - gravity=gravity) + self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. # For the player, we set the damping to a lower value, which increases @@ -129,13 +131,15 @@ def setup(self): # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. - self.physics_engine.add_sprite(self.player_sprite, - friction=PLAYER_FRICTION, - mass=PLAYER_MASS, - moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, - collision_type="player", - max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, - max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) + self.physics_engine.add_sprite( + self.player_sprite, + friction=PLAYER_FRICTION, + mass=PLAYER_MASS, + moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, + collision_type="player", + max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, + max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED, + ) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't @@ -144,38 +148,41 @@ def setup(self): # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. - self.physics_engine.add_sprite_list(self.wall_list, - friction=WALL_FRICTION, - collision_type="wall", - body_type=arcade.PymunkPhysicsEngine.STATIC) + self.physics_engine.add_sprite_list( + self.wall_list, + friction=WALL_FRICTION, + collision_type="wall", + body_type=arcade.PymunkPhysicsEngine.STATIC, + ) # Create the items - self.physics_engine.add_sprite_list(self.item_list, - friction=DYNAMIC_ITEM_FRICTION, - collision_type="item") + self.physics_engine.add_sprite_list( + self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item" + ) def on_key_press(self, key, modifiers): - """Called whenever a key is pressed. """ + """Called whenever a key is pressed.""" pass def on_key_release(self, key, modifiers): - """Called when the user releases a key. """ + """Called when the user releases a key.""" pass def on_update(self, delta_time): - """ Movement and game logic """ + """Movement and game logic""" self.physics_engine.step() def on_draw(self): - """ Draw everything """ + """Draw everything""" self.clear() self.wall_list.draw() self.bullet_list.draw() self.item_list.draw() self.player_list.draw() + def main(): - """ Main function """ + """Main function""" window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run() diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_06.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_06.py index 29847d9611..267adb3edf 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_06.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_06.py @@ -1,7 +1,7 @@ """ Example of Pymunk Physics Engine Platformer """ -from typing import Optional + import arcade SCREEN_TITLE = "PyMunk Platformer" @@ -48,36 +48,37 @@ # Force applied while on the ground PLAYER_MOVE_FORCE_ON_GROUND = 8000 + class GameWindow(arcade.Window): - """ Main Window """ + """Main Window""" def __init__(self, width, height, title): - """ Create the variables """ + """Create the variables""" # Init the parent class super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[arcade.Sprite] = None + self.player_sprite: arcade.Sprite | None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList | None = None + self.wall_list: arcade.SpriteList | None = None + self.bullet_list: arcade.SpriteList | None = None + self.item_list: arcade.SpriteList | None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON def setup(self): - """ Set up everything with the game """ + """Set up everything with the game""" # Create the sprite lists self.player_list = arcade.SpriteList() @@ -94,8 +95,10 @@ def setup(self): self.item_list = tile_map.sprite_lists["Dynamic Items"] # Create player sprite - self.player_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", - SPRITE_SCALING_PLAYER) + self.player_sprite = arcade.Sprite( + ":resources:images/animated_characters/female_person/femalePerson_idle.png", + SPRITE_SCALING_PLAYER, + ) # Set player location grid_x = 1 grid_y = 1 @@ -118,8 +121,7 @@ def setup(self): gravity = (0, -GRAVITY) # Create the physics engine - self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, - gravity=gravity) + self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. # For the player, we set the damping to a lower value, which increases @@ -131,13 +133,15 @@ def setup(self): # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. - self.physics_engine.add_sprite(self.player_sprite, - friction=PLAYER_FRICTION, - mass=PLAYER_MASS, - moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, - collision_type="player", - max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, - max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) + self.physics_engine.add_sprite( + self.player_sprite, + friction=PLAYER_FRICTION, + mass=PLAYER_MASS, + moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, + collision_type="player", + max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, + max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED, + ) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't @@ -146,18 +150,20 @@ def setup(self): # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. - self.physics_engine.add_sprite_list(self.wall_list, - friction=WALL_FRICTION, - collision_type="wall", - body_type=arcade.PymunkPhysicsEngine.STATIC) + self.physics_engine.add_sprite_list( + self.wall_list, + friction=WALL_FRICTION, + collision_type="wall", + body_type=arcade.PymunkPhysicsEngine.STATIC, + ) # Create the items - self.physics_engine.add_sprite_list(self.item_list, - friction=DYNAMIC_ITEM_FRICTION, - collision_type="item") + self.physics_engine.add_sprite_list( + self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item" + ) def on_key_press(self, key, modifiers): - """Called whenever a key is pressed. """ + """Called whenever a key is pressed.""" if key == arcade.key.LEFT: self.left_pressed = True @@ -165,7 +171,7 @@ def on_key_press(self, key, modifiers): self.right_pressed = True def on_key_release(self, key, modifiers): - """Called when the user releases a key. """ + """Called when the user releases a key.""" if key == arcade.key.LEFT: self.left_pressed = False @@ -173,7 +179,7 @@ def on_key_release(self, key, modifiers): self.right_pressed = False def on_update(self, delta_time): - """ Movement and game logic """ + """Movement and game logic""" # Update player forces based on keys pressed if self.left_pressed and not self.right_pressed: @@ -196,15 +202,16 @@ def on_update(self, delta_time): self.physics_engine.step() def on_draw(self): - """ Draw everything """ + """Draw everything""" self.clear() self.wall_list.draw() self.bullet_list.draw() self.item_list.draw() self.player_list.draw() + def main(): - """ Main function """ + """Main function""" window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run() diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_07.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_07.py index acf86426d8..eb2f29dc06 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_07.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_07.py @@ -65,20 +65,20 @@ def __init__(self, width, height, title): super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[arcade.Sprite] = None + self.player_sprite: arcade.Sprite|None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList|None = None + self.wall_list: arcade.SpriteList|None = None + self.bullet_list: arcade.SpriteList|None = None + self.item_list: arcade.SpriteList|None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_08.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_08.py index 7c871bcc5a..b2c28e1cb8 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_08.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_08.py @@ -1,7 +1,7 @@ """ Example of Pymunk Physics Engine Platformer """ -from typing import Optional + import arcade SCREEN_TITLE = "PyMunk Platformer" @@ -66,9 +66,10 @@ class PlayerSprite(arcade.Sprite): - """ Player Sprite """ + """Player Sprite""" + def __init__(self): - """ Init """ + """Init""" # Let parent initialize super().__init__(scale=SPRITE_SCALING_PLAYER) @@ -83,7 +84,7 @@ def __init__(self): # Load textures for idle, jump, and fall states idle_texture = arcade.load_texture(f"{main_path}_idle.png") jump_texture = arcade.load_texture(f"{main_path}_jump.png") - fall_texture = arcade.load_texture(f"{main_path}_fall.png") + fall_texture = arcade.load_texture(f"{main_path}_fall.png") # Make pairs of textures facing left and right self.idle_texture_pair = idle_texture, idle_texture.flip_left_right() self.jump_texture_pair = jump_texture, jump_texture.flip_left_right() @@ -108,7 +109,7 @@ def __init__(self): self.x_odometer = 0 def pymunk_moved(self, physics_engine, dx, dy, d_angle): - """ Handle being moved by the pymunk engine """ + """Handle being moved by the pymunk engine""" # Figure out if we need to face left or right if dx < -DEAD_ZONE and self.character_face_direction == RIGHT_FACING: self.character_face_direction = LEFT_FACING @@ -137,7 +138,6 @@ def pymunk_moved(self, physics_engine, dx, dy, d_angle): # Have we moved far enough to change the texture? if abs(self.x_odometer) > DISTANCE_TO_CHANGE_TEXTURE: - # Reset the odometer self.x_odometer = 0 @@ -149,35 +149,35 @@ def pymunk_moved(self, physics_engine, dx, dy, d_angle): class GameWindow(arcade.Window): - """ Main Window """ + """Main Window""" def __init__(self, width, height, title): - """ Create the variables """ + """Create the variables""" # Init the parent class super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[PlayerSprite] = None + self.player_sprite: PlayerSprite | None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList | None = None + self.wall_list: arcade.SpriteList | None = None + self.bullet_list: arcade.SpriteList | None = None + self.item_list: arcade.SpriteList | None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON def setup(self): - """ Set up everything with the game """ + """Set up everything with the game""" # Create the sprite lists self.player_list = arcade.SpriteList() @@ -218,8 +218,7 @@ def setup(self): gravity = (0, -GRAVITY) # Create the physics engine - self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, - gravity=gravity) + self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. # For the player, we set the damping to a lower value, which increases @@ -231,13 +230,15 @@ def setup(self): # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. - self.physics_engine.add_sprite(self.player_sprite, - friction=PLAYER_FRICTION, - mass=PLAYER_MASS, - moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, - collision_type="player", - max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, - max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) + self.physics_engine.add_sprite( + self.player_sprite, + friction=PLAYER_FRICTION, + mass=PLAYER_MASS, + moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, + collision_type="player", + max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, + max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED, + ) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't @@ -246,18 +247,20 @@ def setup(self): # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. - self.physics_engine.add_sprite_list(self.wall_list, - friction=WALL_FRICTION, - collision_type="wall", - body_type=arcade.PymunkPhysicsEngine.STATIC) + self.physics_engine.add_sprite_list( + self.wall_list, + friction=WALL_FRICTION, + collision_type="wall", + body_type=arcade.PymunkPhysicsEngine.STATIC, + ) # Create the items - self.physics_engine.add_sprite_list(self.item_list, - friction=DYNAMIC_ITEM_FRICTION, - collision_type="item") + self.physics_engine.add_sprite_list( + self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item" + ) def on_key_press(self, key, modifiers): - """Called whenever a key is pressed. """ + """Called whenever a key is pressed.""" if key == arcade.key.LEFT: self.left_pressed = True @@ -271,7 +274,7 @@ def on_key_press(self, key, modifiers): self.physics_engine.apply_impulse(self.player_sprite, impulse) def on_key_release(self, key, modifiers): - """Called when the user releases a key. """ + """Called when the user releases a key.""" if key == arcade.key.LEFT: self.left_pressed = False @@ -279,7 +282,7 @@ def on_key_release(self, key, modifiers): self.right_pressed = False def on_update(self, delta_time): - """ Movement and game logic """ + """Movement and game logic""" is_on_ground = self.physics_engine.is_on_ground(self.player_sprite) # Update player forces based on keys pressed @@ -309,15 +312,16 @@ def on_update(self, delta_time): self.physics_engine.step() def on_draw(self): - """ Draw everything """ + """Draw everything""" self.clear() self.wall_list.draw() self.bullet_list.draw() self.item_list.draw() self.player_list.draw() + def main(): - """ Main function """ + """Main function""" window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run() diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_09.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_09.py index 5c410f02d2..c344ddbae1 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_09.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_09.py @@ -3,6 +3,7 @@ """ import math from typing import Optional + import arcade SCREEN_TITLE = "PyMunk Platformer" @@ -168,20 +169,20 @@ def __init__(self, width, height, title): super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[PlayerSprite] = None + self.player_sprite: PlayerSprite|None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList|None = None + self.wall_list: arcade.SpriteList|None = None + self.bullet_list: arcade.SpriteList|None = None + self.item_list: arcade.SpriteList|None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_10.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_10.py index a1ec9f0fe7..b3381953c2 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_10.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_10.py @@ -177,20 +177,20 @@ def __init__(self, width, height, title): super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[PlayerSprite] = None + self.player_sprite: PlayerSprite|None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList|None = None + self.wall_list: arcade.SpriteList|None = None + self.bullet_list: arcade.SpriteList|None = None + self.item_list: arcade.SpriteList|None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_11.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_11.py index cd76c04232..0a340a9313 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_11.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_11.py @@ -3,6 +3,7 @@ """ import math from typing import Optional + import arcade SCREEN_TITLE = "PyMunk Platformer" @@ -177,21 +178,21 @@ def __init__(self, width, height, title): super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[PlayerSprite] = None + self.player_sprite: PlayerSprite|None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None - self.moving_sprites_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList|None = None + self.wall_list: arcade.SpriteList|None = None + self.bullet_list: arcade.SpriteList|None = None + self.item_list: arcade.SpriteList|None = None + self.moving_sprites_list: arcade.SpriteList|None = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False # Physics engine - self.physics_engine = Optional[arcade.PymunkPhysicsEngine] + self.physics_engine: arcade.PymunkPhysicsEngine | None = None # Set background color self.background_color = arcade.color.AMAZON diff --git a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_12.py b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_12.py index b1d20eadb7..45661a82b1 100644 --- a/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_12.py +++ b/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_12.py @@ -1,6 +1,7 @@ """ Example of Pymunk Physics Engine Platformer """ + import math from typing import Optional import arcade @@ -76,11 +77,12 @@ class PlayerSprite(arcade.Sprite): - """ Player Sprite """ - def __init__(self, - ladder_list: arcade.SpriteList, - hit_box_algorithm: arcade.hitbox.HitBoxAlgorithm): - """ Init """ + """Player Sprite""" + + def __init__( + self, ladder_list: arcade.SpriteList, hit_box_algorithm: arcade.hitbox.HitBoxAlgorithm + ): + """Init""" # Let parent initialize super().__init__(scale=SPRITE_SCALING_PLAYER) @@ -92,7 +94,9 @@ def __init__(self, # main_path = ":resources:images/animated_characters/zombie/zombie" # main_path = ":resources:images/animated_characters/robot/robot" - idle_texture = arcade.load_texture(f"{main_path}_idle.png", hit_box_algorithm=hit_box_algorithm) + idle_texture = arcade.load_texture( + f"{main_path}_idle.png", hit_box_algorithm=hit_box_algorithm + ) jump_texture = arcade.load_texture(f"{main_path}_jump.png") fall_texture = arcade.load_texture(f"{main_path}_fall.png") @@ -131,7 +135,7 @@ def __init__(self, self.is_on_ladder = False def pymunk_moved(self, physics_engine, dx, dy, d_angle): - """ Handle being moved by the pymunk engine """ + """Handle being moved by the pymunk engine""" # Figure out if we need to face left or right if dx < -DEAD_ZONE and self.character_face_direction == RIGHT_FACING: self.character_face_direction = LEFT_FACING @@ -162,7 +166,6 @@ def pymunk_moved(self, physics_engine, dx, dy, d_angle): if self.is_on_ladder and not is_on_ground: # Have we moved far enough to change the texture? if abs(self.y_odometer) > DISTANCE_TO_CHANGE_TEXTURE: - # Reset the odometer self.y_odometer = 0 @@ -190,7 +193,6 @@ def pymunk_moved(self, physics_engine, dx, dy, d_angle): # Have we moved far enough to change the texture? if abs(self.x_odometer) > DISTANCE_TO_CHANGE_TEXTURE: - # Reset the odometer self.x_odometer = 0 @@ -200,33 +202,36 @@ def pymunk_moved(self, physics_engine, dx, dy, d_angle): self.cur_texture = 0 self.texture = self.walk_textures[self.cur_texture][self.character_face_direction] + class BulletSprite(arcade.SpriteSolidColor): - """ Bullet Sprite """ + """Bullet Sprite""" + def pymunk_moved(self, physics_engine, dx, dy, d_angle): - """ Handle when the sprite is moved by the physics engine. """ + """Handle when the sprite is moved by the physics engine.""" # If the bullet falls below the screen, remove it if self.center_y < -100: self.remove_from_sprite_lists() + class GameWindow(arcade.Window): - """ Main Window """ + """Main Window""" def __init__(self, width, height, title): - """ Create the variables """ + """Create the variables""" # Init the parent class super().__init__(width, height, title) # Player sprite - self.player_sprite: Optional[PlayerSprite] = None + self.player_sprite: PlayerSprite | None = None # Sprite lists we need - self.player_list: Optional[arcade.SpriteList] = None - self.wall_list: Optional[arcade.SpriteList] = None - self.bullet_list: Optional[arcade.SpriteList] = None - self.item_list: Optional[arcade.SpriteList] = None - self.moving_sprites_list: Optional[arcade.SpriteList] = None - self.ladder_list: Optional[arcade.SpriteList] = None + self.player_list: arcade.SpriteList | None = None + self.wall_list: arcade.SpriteList | None = None + self.bullet_list: arcade.SpriteList | None = None + self.item_list: arcade.SpriteList | None = None + self.moving_sprites_list: arcade.SpriteList | None = None + self.ladder_list: arcade.SpriteList | None = None # Track the current state of what key is pressed self.left_pressed: bool = False @@ -241,7 +246,7 @@ def __init__(self, width, height, title): self.background_color = arcade.color.AMAZON def setup(self): - """ Set up everything with the game """ + """Set up everything with the game""" # Create the sprite lists self.player_list = arcade.SpriteList() @@ -257,10 +262,12 @@ def setup(self): self.wall_list = tile_map.sprite_lists["Platforms"] self.item_list = tile_map.sprite_lists["Dynamic Items"] self.ladder_list = tile_map.sprite_lists["Ladders"] - self.moving_sprites_list = tile_map.sprite_lists['Moving Platforms'] + self.moving_sprites_list = tile_map.sprite_lists["Moving Platforms"] # Create player sprite - self.player_sprite = PlayerSprite(self.ladder_list, hit_box_algorithm=arcade.hitbox.algo_detailed) + self.player_sprite = PlayerSprite( + self.ladder_list, hit_box_algorithm=arcade.hitbox.algo_detailed + ) # Set player location grid_x = 1 @@ -284,17 +291,16 @@ def setup(self): gravity = (0, -GRAVITY) # Create the physics engine - self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, - gravity=gravity) + self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) def wall_hit_handler(bullet_sprite, _wall_sprite, _arbiter, _space, _data): - """ Called for bullet/wall collision """ + """Called for bullet/wall collision""" bullet_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler("bullet", "wall", post_handler=wall_hit_handler) def item_hit_handler(bullet_sprite, item_sprite, _arbiter, _space, _data): - """ Called for bullet/wall collision """ + """Called for bullet/wall collision""" bullet_sprite.remove_from_sprite_lists() item_sprite.remove_from_sprite_lists() @@ -310,13 +316,15 @@ def item_hit_handler(bullet_sprite, item_sprite, _arbiter, _space, _data): # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. - self.physics_engine.add_sprite(self.player_sprite, - friction=PLAYER_FRICTION, - mass=PLAYER_MASS, - moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, - collision_type="player", - max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, - max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) + self.physics_engine.add_sprite( + self.player_sprite, + friction=PLAYER_FRICTION, + mass=PLAYER_MASS, + moment_of_inertia=arcade.PymunkPhysicsEngine.MOMENT_INF, + collision_type="player", + max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, + max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED, + ) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't @@ -325,22 +333,25 @@ def item_hit_handler(bullet_sprite, item_sprite, _arbiter, _space, _data): # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. - self.physics_engine.add_sprite_list(self.wall_list, - friction=WALL_FRICTION, - collision_type="wall", - body_type=arcade.PymunkPhysicsEngine.STATIC) + self.physics_engine.add_sprite_list( + self.wall_list, + friction=WALL_FRICTION, + collision_type="wall", + body_type=arcade.PymunkPhysicsEngine.STATIC, + ) # Create the items - self.physics_engine.add_sprite_list(self.item_list, - friction=DYNAMIC_ITEM_FRICTION, - collision_type="item") + self.physics_engine.add_sprite_list( + self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item" + ) # Add kinematic sprites - self.physics_engine.add_sprite_list(self.moving_sprites_list, - body_type=arcade.PymunkPhysicsEngine.KINEMATIC) + self.physics_engine.add_sprite_list( + self.moving_sprites_list, body_type=arcade.PymunkPhysicsEngine.KINEMATIC + ) def on_key_press(self, key, modifiers): - """Called whenever a key is pressed. """ + """Called whenever a key is pressed.""" if key in (arcade.key.LEFT, arcade.key.A): self.left_pressed = True @@ -349,8 +360,10 @@ def on_key_press(self, key, modifiers): elif key in (arcade.key.UP, arcade.key.W): self.up_pressed = True # find out if player is standing on ground, and not on a ladder - if self.physics_engine.is_on_ground(self.player_sprite) \ - and not self.player_sprite.is_on_ladder: + if ( + self.physics_engine.is_on_ground(self.player_sprite) + and not self.player_sprite.is_on_ladder + ): # She is! Go ahead and jump impulse = (0, PLAYER_JUMP_IMPULSE) self.physics_engine.apply_impulse(self.player_sprite, impulse) @@ -358,7 +371,7 @@ def on_key_press(self, key, modifiers): self.down_pressed = True def on_key_release(self, key, modifiers): - """Called when the user releases a key. """ + """Called when the user releases a key.""" if key in (arcade.key.LEFT, arcade.key.A): self.left_pressed = False @@ -370,7 +383,7 @@ def on_key_release(self, key, modifiers): self.down_pressed = False def on_mouse_press(self, x, y, button, modifiers): - """ Called whenever the mouse button is clicked. """ + """Called whenever the mouse button is clicked.""" bullet = BulletSprite(width=20, height=5, color=arcade.color.DARK_YELLOW) self.bullet_list.append(bullet) @@ -411,20 +424,22 @@ def on_mouse_press(self, x, y, button, modifiers): bullet_gravity = (0, -BULLET_GRAVITY) # Add the sprite. This needs to be done AFTER setting the fields above. - self.physics_engine.add_sprite(bullet, - mass=BULLET_MASS, - damping=1.0, - friction=0.6, - collision_type="bullet", - gravity=bullet_gravity, - elasticity=0.9) + self.physics_engine.add_sprite( + bullet, + mass=BULLET_MASS, + damping=1.0, + friction=0.6, + collision_type="bullet", + gravity=bullet_gravity, + elasticity=0.9, + ) # Add force to bullet force = (BULLET_MOVE_FORCE, 0) self.physics_engine.apply_force(bullet, force) def on_update(self, delta_time): - """ Movement and game logic """ + """Movement and game logic""" is_on_ground = self.physics_engine.is_on_ground(self.player_sprite) # Update player forces based on keys pressed @@ -471,31 +486,42 @@ def on_update(self, delta_time): # For each moving sprite, see if we've reached a boundary and need to # reverse course. for moving_sprite in self.moving_sprites_list: - if moving_sprite.boundary_right and \ - moving_sprite.change_x > 0 and \ - moving_sprite.right > moving_sprite.boundary_right: + if ( + moving_sprite.boundary_right + and moving_sprite.change_x > 0 + and moving_sprite.right > moving_sprite.boundary_right + ): moving_sprite.change_x *= -1 - elif moving_sprite.boundary_left and \ - moving_sprite.change_x < 0 and \ - moving_sprite.left > moving_sprite.boundary_left: + elif ( + moving_sprite.boundary_left + and moving_sprite.change_x < 0 + and moving_sprite.left > moving_sprite.boundary_left + ): moving_sprite.change_x *= -1 - if moving_sprite.boundary_top and \ - moving_sprite.change_y > 0 and \ - moving_sprite.top > moving_sprite.boundary_top: + if ( + moving_sprite.boundary_top + and moving_sprite.change_y > 0 + and moving_sprite.top > moving_sprite.boundary_top + ): moving_sprite.change_y *= -1 - elif moving_sprite.boundary_bottom and \ - moving_sprite.change_y < 0 and \ - moving_sprite.bottom < moving_sprite.boundary_bottom: + elif ( + moving_sprite.boundary_bottom + and moving_sprite.change_y < 0 + and moving_sprite.bottom < moving_sprite.boundary_bottom + ): moving_sprite.change_y *= -1 # Figure out and set our moving platform velocity. # Pymunk uses velocity is in pixels per second. If we instead have # pixels per frame, we need to convert. - velocity = (moving_sprite.change_x * 1 / delta_time, moving_sprite.change_y * 1 / delta_time) + velocity = ( + moving_sprite.change_x * 1 / delta_time, + moving_sprite.change_y * 1 / delta_time, + ) self.physics_engine.set_velocity(moving_sprite, velocity) def on_draw(self): - """ Draw everything """ + """Draw everything""" self.clear() self.wall_list.draw() self.ladder_list.draw() @@ -509,8 +535,9 @@ def on_draw(self): # for item in self.item_list: # item.draw_hit_box(arcade.color.RED) + def main(): - """ Main function """ + """Main function""" window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run() diff --git a/tests/unit/color/test_module_color.py b/tests/unit/color/test_module_color.py index 16c221d228..0ab742fb1a 100644 --- a/tests/unit/color/test_module_color.py +++ b/tests/unit/color/test_module_color.py @@ -1,6 +1,6 @@ - def test_colors(): from arcade import color + names = color.__dict__.keys() - # number of colors + 1 real import + 1 annotations - assert 1016 + 1 + 1 == len(names) + # number of colors + 1 real import + assert 1016 + 1 == len(names) diff --git a/tests/unit/color/test_module_csscolor.py b/tests/unit/color/test_module_csscolor.py index c23e062e65..f238c95ecb 100644 --- a/tests/unit/color/test_module_csscolor.py +++ b/tests/unit/color/test_module_csscolor.py @@ -2,5 +2,5 @@ def test_csscolors(): from arcade import csscolor names = csscolor.__dict__.keys() - # number of colors + 1 import + 1 annotations - assert 156 + 1 + 1 == len(names) + # number of colors + 1 import + assert 156 + 1 == len(names) From a85dbd0b2505638596859d14c2b8aee3d303373d Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Fri, 28 Mar 2025 16:34:51 +0100 Subject: [PATCH 3/5] fix linter --- arcade/particles/emitter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arcade/particles/emitter.py b/arcade/particles/emitter.py index f6b8a115fc..ec6b248301 100644 --- a/arcade/particles/emitter.py +++ b/arcade/particles/emitter.py @@ -2,6 +2,7 @@ Emitter - Invisible object that determines when Particles are emitted, actually emits them, and manages them over their lifetime """ + from __future__ import annotations from typing import Callable, cast From 27c65c00e3d0e640cab89458289575cf024a8738 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Fri, 28 Mar 2025 16:37:22 +0100 Subject: [PATCH 4/5] fix future import --- util/doc_helpers/import_resolver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/doc_helpers/import_resolver.py b/util/doc_helpers/import_resolver.py index ffb3f2d9c2..9d99d4aafe 100644 --- a/util/doc_helpers/import_resolver.py +++ b/util/doc_helpers/import_resolver.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import ast import dataclasses from pathlib import Path @@ -9,9 +11,11 @@ # Build a tree using the ast module looking at the __init__ files # and recurse the tree to find the lowest import of a member. + @dataclasses.dataclass class ImportNode: """A node in the import tree.""" + name: str parent: ImportNode | None = None children: list[ImportNode] = dataclasses.field(default_factory=list) @@ -67,6 +71,7 @@ def print_tree(self, depth=0): @dataclasses.dataclass class Import: """Unified representation of an import statement.""" + name: str # name of the member module: str # The module this import is from from_module: str # The module the member was imported from @@ -116,7 +121,7 @@ def _parse_import_node_recursive( imp = Import( name=alias.name.split(".")[-1], module=full_module_path, - from_module=".".join(alias.name.split(".")[:-1]) + from_module=".".join(alias.name.split(".")[:-1]), ) node.imports.append(imp) elif isinstance(ast_node, ast.ImportFrom): From f65847adf5d961ef0f1882ae197e428ce06a3103 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Fri, 28 Mar 2025 17:28:46 +0100 Subject: [PATCH 5/5] Tutorial line fixes --- doc/tutorials/card_game/index.rst | 2 +- doc/tutorials/pymunk_platformer/index.rst | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/tutorials/card_game/index.rst b/doc/tutorials/card_game/index.rst index 5cc666cd4d..7c080d84fb 100644 --- a/doc/tutorials/card_game/index.rst +++ b/doc/tutorials/card_game/index.rst @@ -549,7 +549,7 @@ so we can go through it again. :caption: Flipping of Bottom Deck :linenos: :pyobject: MyGame.on_mouse_press - :emphasize-lines: 15-33, 56-71 + :emphasize-lines: 16-34, 59-74 Test ~~~~ diff --git a/doc/tutorials/pymunk_platformer/index.rst b/doc/tutorials/pymunk_platformer/index.rst index 7cf41c8d5a..4255867afe 100644 --- a/doc/tutorials/pymunk_platformer/index.rst +++ b/doc/tutorials/pymunk_platformer/index.rst @@ -69,7 +69,7 @@ When you run this program, the screen should be larger. :caption: Adding some constants :linenos: :lines: 1-29 - :emphasize-lines: 4-26 + :emphasize-lines: 6-24 * :ref:`pymunk_demo_platformer_02` * :ref:`pymunk_demo_platformer_02_diff` @@ -223,8 +223,8 @@ We'll apply a different force later, if the player happens to be airborne. .. literalinclude:: pymunk_demo_platformer_06.py :caption: Add Player Movement - Constants and Attributes :linenos: - :lines: 48-71 - :emphasize-lines: 1-2, 22-24 + :lines: 48-75 + :emphasize-lines: 1-2, 23-25 We need to track if the left/right keys are held down. To do this we define instance variables ``left_pressed`` and ``right_pressed``. These are set to @@ -234,7 +234,7 @@ appropriate values in the key press and release handlers. :caption: Handle Key Up and Down Events :linenos: :lines: 159-173 - :emphasize-lines: 4-7, 12-15 + :emphasize-lines: 2-5, 10-13 Finally, we need to apply the correct force in ``on_update``. Force is specified in a tuple with horizontal force first, and vertical force second. @@ -245,7 +245,7 @@ We also set the friction when we are moving to zero, and when we are not moving .. literalinclude:: pymunk_demo_platformer_06.py :caption: Apply Force to Move Player :linenos: - :lines: 175-196 + :lines: 181-199 :emphasize-lines: 4-19 * :ref:`pymunk_demo_platformer_06`