Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 7 additions & 7 deletions buildconfig/stubs/pygame/sprite.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ from pygame.typing import Point, RectLike
# Some sprite functions only need objects with certain attributes, not always a sprite
class _HasRect(Protocol):
@property
def rect(self) -> Optional[Union[FRect, Rect]]: ...
def rect(self) -> Union[FRect, Rect]: ...

# image in addition to rect
class _HasImageAndRect(_HasRect, Protocol):
@property
def image(self) -> Optional[Surface]: ...
def image(self) -> Surface: ...

# mask in addition to rect
class _HasMaskAndRect(_HasRect, Protocol):
Expand All @@ -44,13 +44,13 @@ class _HasMaskAndRect(_HasRect, Protocol):

class Sprite(_HasImageAndRect):
@property
def image(self) -> Optional[Surface]: ...
def image(self) -> Surface: ...
@image.setter
def image(self, value: Optional[Surface]) -> None: ...
def image(self, value: Surface) -> None: ...
@property
def rect(self) -> Optional[Union[FRect, Rect]]: ...
def rect(self) -> Union[FRect, Rect]: ...
@rect.setter
def rect(self, value: Optional[Union[FRect, Rect]]) -> None: ...
def rect(self, value: Union[FRect, Rect]) -> None: ...
@property
def layer(self) -> int: ...
@layer.setter
Expand All @@ -68,7 +68,7 @@ class Sprite(_HasImageAndRect):
class DirtySprite(Sprite):
dirty: int
blendmode: int
source_rect: Union[FRect, Rect]
source_rect: Optional[Union[FRect, Rect]]
visible: int
_layer: int

Expand Down
26 changes: 6 additions & 20 deletions src_py/sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@
# specialized cases.

import types
from typing import Optional
from typing import Union
from warnings import warn

import pygame
from pygame.mask import from_surface
from pygame.rect import Rect
from pygame.rect import FRect, Rect
from pygame.surface import Surface
from pygame.time import get_ticks


Expand All @@ -109,29 +110,14 @@ class Sprite:

"""

image: Surface
rect: Union[Rect, FRect]

def __init__(self, *groups):
self.__g = {} # The groups the sprite is in
self.__image: Optional[pygame.surface.Surface] = None
self.__rect: Optional[pygame.rect.Rect] = None
if groups:
self.add(*groups)

@property
def image(self):
return self.__image

@image.setter
def image(self, value: Optional[pygame.surface.Surface]):
self.__image = value

@property
def rect(self):
return self.__rect

@rect.setter
def rect(self, value: Optional[pygame.rect.Rect]):
self.__rect = value

def add(self, *groups):
"""add the sprite to groups

Expand Down
Loading