Skip to content

More pyright fixes #1787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arcade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def configure_logging(level: Optional[int] = None):
# Load additional game controller mappings to Pyglet
if not pyglet.options['headless']:
try:
import pyglet.input.controller
mappings_file = resources.resolve(":system:gamecontrollerdb.txt")
pyglet.input.controller.add_mappings_from_file(mappings_file)
except AssertionError:
Expand Down
1 change: 1 addition & 0 deletions arcade/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pyglet

import pyglet.gl as gl
import pyglet.window.mouse
from pyglet.canvas.base import ScreenMode

import arcade
Expand Down
2 changes: 1 addition & 1 deletion arcade/gl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def texture(
data: Optional[BufferProtocol] = None,
wrap_x: Optional[PyGLenum] = None,
wrap_y: Optional[PyGLenum] = None,
filter: Optional[Tuple[GLenumLike, GLenumLike]] = None,
filter: Optional[Tuple[PyGLenum, PyGLenum]] = None,
samples: int = 0,
immutable: bool = False,
) -> Texture2D:
Expand Down
2 changes: 1 addition & 1 deletion arcade/gl/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(
components: int = 4,
dtype: str = "f1",
data: Optional[BufferProtocol] = None,
filter: Optional[Tuple[gl.GLuint, gl.GLuint]] = None,
filter: Optional[Tuple[PyGLuint, PyGLuint]] = None,
wrap_x: Optional[PyGLuint] = None,
wrap_y: Optional[PyGLuint] = None,
target=gl.GL_TEXTURE_2D,
Expand Down
2 changes: 1 addition & 1 deletion arcade/gl/vertex_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def render_indirect(
program: Program,
buffer: Buffer,
*,
mode: Optional[gl.GLuint] = None,
mode: Optional[GLuintLike] = None,
count: int = -1,
first: int = 0,
stride: int = 0,
Expand Down
4 changes: 2 additions & 2 deletions arcade/gui/widgets/dropdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
from typing import Optional, List
from typing import Optional, List, Union

import arcade
from arcade.gui.events import UIOnChangeEvent, UIOnClickEvent
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
width: float = 100,
height: float = 100,
default: Optional[str] = None,
options: Optional[List[str]] = None,
options: Optional[List[Union[str, None]]] = None,
style=None, **kwargs
):
if style is None:
Expand Down
2 changes: 1 addition & 1 deletion arcade/joysticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_joysticks() -> List[Joystick]:

:return: List of game controllers
"""
return pyglet.input.get_joysticks()
return pyglet.input.get_joysticks() # type: ignore # pending https://github.com/pyglet/pyglet/issues/842


def get_game_controllers() -> List[Joystick]:
Expand Down
2 changes: 1 addition & 1 deletion arcade/perf_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(
self._vertical_axis_text_objects.append(
arcade.Text(
"0", # Ensure the lowest y axis label is always 0
self._left_x, y_level,
self._left_x, int(y_level),
self._font_color, self._font_size,
anchor_x="right", anchor_y="center"))
self._grid_lines.append(
Expand Down
1 change: 1 addition & 0 deletions arcade/sprite/colored.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PIL
import PIL.Image

from arcade import cache, hitbox
from arcade.texture import (
Expand Down
12 changes: 7 additions & 5 deletions arcade/sprite_list/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def check_for_collision(sprite1: SpriteType, sprite2: SpriteType) -> bool:
return _check_for_collision(sprite1, sprite2)


def _check_for_collision(sprite1: SpriteType, sprite2: SpriteType) -> bool:
def _check_for_collision(sprite1: BasicSprite, sprite2: BasicSprite) -> bool:
"""
Check for collision between two sprites.

Expand Down Expand Up @@ -130,7 +130,7 @@ def _check_for_collision(sprite1: SpriteType, sprite2: SpriteType) -> bool:
)


def _get_nearby_sprites(sprite: SpriteType, sprite_list: SpriteList) -> List[SpriteType]:
def _get_nearby_sprites(sprite: BasicSprite, sprite_list: SpriteList[SpriteType]) -> List[SpriteType]:
sprite_count = len(sprite_list)
if sprite_count == 0:
return []
Expand Down Expand Up @@ -229,8 +229,8 @@ def check_for_collision_with_list(


def check_for_collision_with_lists(
sprite: SpriteType,
sprite_lists: Iterable[SpriteList],
sprite: BasicSprite,
sprite_lists: Iterable[SpriteList[SpriteType]],
method=1,
) -> List[SpriteType]:
"""
Expand All @@ -246,7 +246,9 @@ def check_for_collision_with_lists(
"""
if __debug__:
if not isinstance(sprite, BasicSprite):
raise TypeError(f"Parameter 1 is not an instance of the Sprite class, it is an instance of {type(sprite)}.")
raise TypeError(
f"Parameter 1 is not an instance of the BasicSprite class, it is an instance of {type(sprite)}."
)

sprites: List[SpriteType] = []
sprites_to_check: Iterable[SpriteType]
Expand Down
3 changes: 2 additions & 1 deletion arcade/sprite_list/spatial_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Dict,
Generic,
)
from arcade.sprite.base import BasicSprite
from arcade.types import Point, IPoint, Rect
from arcade.sprite import SpriteType

Expand Down Expand Up @@ -92,7 +93,7 @@ def remove(self, sprite: SpriteType) -> None:
# Delete the sprite from the bucket tracker
del self.buckets_for_sprite[sprite]

def get_sprites_near_sprite(self, sprite: SpriteType) -> Set[SpriteType]:
def get_sprites_near_sprite(self, sprite: BasicSprite) -> Set[SpriteType]:
"""
Get all the sprites that are in the same buckets as the given sprite.

Expand Down
2 changes: 1 addition & 1 deletion arcade/sprite_list/sprite_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(
from .spatial_hash import SpatialHash

self._spatial_hash_cell_size = spatial_hash_cell_size
self.spatial_hash: Optional[SpatialHash] = None
self.spatial_hash: Optional[SpatialHash[SpriteType]] = None
if use_spatial_hash:
self.spatial_hash = SpatialHash(cell_size=self._spatial_hash_cell_size)

Expand Down
14 changes: 7 additions & 7 deletions arcade/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class Text:
def __init__(
self,
text: str,
start_x: float,
start_y: float,
start_x: int,
start_y: int,
color: RGBOrA255 = arcade.color.WHITE,
font_size: float = 12,
width: Optional[int] = 0,
Expand All @@ -193,7 +193,7 @@ def __init__(
rotation: float = 0,
batch: Optional[pyglet.graphics.Batch] = None,
group: Optional[pyglet.graphics.Group] = None,
start_z: float = 0
start_z: int = 0
):
if align != "center" and align != "left" and align != "right":
raise ValueError("The 'align' parameter must be equal to 'left', 'right', or 'center'.")
Expand All @@ -214,7 +214,7 @@ def __init__(
bold=bold,
italic=italic,
multiline=multiline,
rotation=rotation,
rotation=rotation, # type: ignore # pending https://github.com/pyglet/pyglet/issues/843
batch=batch,
group=group
)
Expand Down Expand Up @@ -662,8 +662,8 @@ def create_text_sprite(
)
def draw_text(
text: Any,
start_x: float,
start_y: float,
start_x: int,
start_y: int,
color: RGBA255 = arcade.color.WHITE,
font_size: float = 12,
width: int = 0,
Expand All @@ -675,7 +675,7 @@ def draw_text(
anchor_y: str = "baseline",
multiline: bool = False,
rotation: float = 0,
start_z: float = 0
start_z: int = 0
):
"""
A simple way for beginners to draw text.
Expand Down
4 changes: 2 additions & 2 deletions arcade/texture/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def file_path(self) -> Optional[Path]:
return self._file_path

@file_path.setter
def file_path(self, path: Path):
def file_path(self, path: Optional[Path]):
self._file_path = path

@property
Expand All @@ -301,7 +301,7 @@ def crop_values(self) -> Optional[Tuple[int, int, int, int]]:
return self._crop_values

@crop_values.setter
def crop_values(self, crop: Tuple[int, int, int, int]):
def crop_values(self, crop: Optional[Tuple[int, int, int, int]]):
self._crop_values = crop

@property
Expand Down