Skip to content

Commit df0b34b

Browse files
committed
enhance typings on Sprite and SpriteList
1 parent b4f9d67 commit df0b34b

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

arcade/scene.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* Control sprite list draw order within the group
1111
"""
1212

13-
from typing import Dict, List, Optional, Union, Iterable, Tuple
13+
from typing import Dict, List, Optional, Union, Iterable
1414

1515
from arcade import Sprite, SpriteList
16-
from arcade.types import Color, RGBA255
16+
from arcade.types import Color, RGBA255, OpenGlFilters, BlendFunctions
1717
from arcade.tilemap import TileMap
1818

1919
from warnings import warn
@@ -432,9 +432,9 @@ def update_animation(
432432
def draw(
433433
self,
434434
names: Optional[Iterable[str]] = None,
435-
filter: Optional[int] = None,
435+
filter: Optional[OpenGlFilters] = None,
436436
pixelated: bool = False,
437-
blend_function: Optional[Union[Tuple[int, int], Tuple[int, int, int, int]]] = None,
437+
blend_function: Optional[BlendFunctions] = None,
438438
**kwargs
439439
) -> None:
440440
"""

arcade/sprite/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Iterable, List, TypeVar
1+
from typing import TYPE_CHECKING, Iterable, List, TypeVar, Any
22

33
import arcade
44
from arcade.types import Point, Color, RGBA255, PointList
@@ -47,7 +47,7 @@ def __init__(
4747
scale: float = 1.0,
4848
center_x: float = 0,
4949
center_y: float = 0,
50-
**kwargs,
50+
**kwargs: Any,
5151
) -> None:
5252
self._position = (center_x, center_y)
5353
self._depth = 0.0

arcade/sprite/sprite.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from arcade import Texture, load_texture
66
from arcade.hitbox import HitBox, RotatableHitBox
77
from arcade.texture import get_default_texture
8-
from arcade.types import PathOrTexture, Point
8+
from arcade.types import PathOrTexture, Point, OpenGlFilters, BlendFunctions
99

1010
from .base import BasicSprite
1111
from .mixins import PymunkMixin
@@ -66,7 +66,7 @@ def __init__(
6666
center_x: float = 0.0,
6767
center_y: float = 0.0,
6868
angle: float = 0.0,
69-
**kwargs,
69+
**kwargs: Any,
7070
):
7171
if isinstance(path_or_texture, Texture):
7272
_texture = path_or_texture
@@ -255,7 +255,7 @@ def properties(self) -> Dict[str, Any]:
255255
return self._properties
256256

257257
@properties.setter
258-
def properties(self, value):
258+
def properties(self, value: Dict[str, Any]):
259259
self._properties = value
260260

261261
# --- Movement methods -----
@@ -313,7 +313,13 @@ def stop(self) -> None:
313313

314314
# ---- Draw Methods ----
315315

316-
def draw(self, *, filter=None, pixelated=None, blend_function=None) -> None:
316+
def draw(
317+
self,
318+
*,
319+
filter: Optional[OpenGlFilters] | None = None,
320+
pixelated: Optional[bool] = None,
321+
blend_function: Optional[BlendFunctions] = None
322+
) -> None:
317323
"""
318324
A debug method which draws the sprite into the current OpenGL context.
319325
@@ -399,7 +405,7 @@ def remove_from_sprite_lists(self) -> None:
399405

400406
self.physics_engines.clear()
401407

402-
def register_physics_engine(self, physics_engine) -> None:
408+
def register_physics_engine(self, physics_engine: Any) -> None:
403409
"""
404410
Register a physics engine on the sprite.
405411
This is only needed if you actually need a reference

arcade/sprite_list/sprite_list.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
get_window,
3232
gl,
3333
)
34-
from arcade.types import Color, RGBA255
34+
from arcade.types import Color, RGBA255, OpenGlFilters, BlendFunctions
3535
from arcade.gl.buffer import Buffer
3636
from arcade.gl.vertex_array import Geometry
3737

@@ -960,7 +960,13 @@ def initialize(self):
960960
"""
961961
self._init_deferred()
962962

963-
def draw(self, *, filter=None, pixelated=None, blend_function=None):
963+
def draw(
964+
self,
965+
*,
966+
filter: Optional[OpenGlFilters] = None,
967+
pixelated: Optional[bool] = None,
968+
blend_function: Optional[BlendFunctions] = None
969+
) -> None:
964970
"""
965971
Draw this list of sprites.
966972

arcade/types.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
Sequence,
1818
Tuple,
1919
Union,
20-
TYPE_CHECKING, TypeVar
20+
TYPE_CHECKING,
21+
TypeVar,
22+
TypeAlias,
23+
Literal,
2124
)
2225
from typing_extensions import Self
2326

@@ -49,6 +52,22 @@
4952

5053
RGBA255OrNormalized = Union[RGBA255, RGBANormalized]
5154

55+
# equivalent to the following filters (under arcade.gl.enums):
56+
# NEAREST, LINEAR, NEAREST_MIPMAP_NEAREST, LINEAR_MIPMAP_NEAREST,
57+
# NEAREST_MIPMAP_LINEAR, LINEAR_MIPMAP_LINEAR
58+
OpenGlFilters: TypeAlias = Union[Literal[9728], Literal[9729], Literal[9984],
59+
Literal[9985], Literal[9986], Literal[9987]]
60+
61+
# equivalent to the following blend_functions (under arcade.gl.enums):
62+
# ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR,
63+
# SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA,
64+
# ONE_MINUS_DST_ALPHA, DST_COLOR, ONE_MINUS_DST_COLOR
65+
BlendFunctions: TypeAlias = Union[Literal[0], Literal[1], Literal[768],
66+
Literal[769], Literal[770], Literal[771],
67+
Literal[772], Literal[773], Literal[774],
68+
Literal[775]]
69+
70+
5271

5372
__all__ = [
5473
"BufferProtocol",

0 commit comments

Comments
 (0)