Skip to content

Commit 4607af4

Browse files
committed
Remove default None initialization and property accessors of sprite rect and surface
1 parent 1c7ad5a commit 4607af4

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

buildconfig/stubs/pygame/sprite.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ from pygame.typing import Point, RectLike
3030
# Some sprite functions only need objects with certain attributes, not always a sprite
3131
class _HasRect(Protocol):
3232
@property
33-
def rect(self) -> Optional[Union[FRect, Rect]]: ...
33+
def rect(self) -> Union[FRect, Rect]: ...
3434

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

4040
# mask in addition to rect
4141
class _HasMaskAndRect(_HasRect, Protocol):
@@ -44,13 +44,13 @@ class _HasMaskAndRect(_HasRect, Protocol):
4444

4545
class Sprite(_HasImageAndRect):
4646
@property
47-
def image(self) -> Optional[Surface]: ...
47+
def image(self) -> Surface: ...
4848
@image.setter
49-
def image(self, value: Optional[Surface]) -> None: ...
49+
def image(self, value: Surface) -> None: ...
5050
@property
51-
def rect(self) -> Optional[Union[FRect, Rect]]: ...
51+
def rect(self) -> Union[FRect, Rect]: ...
5252
@rect.setter
53-
def rect(self, value: Optional[Union[FRect, Rect]]) -> None: ...
53+
def rect(self, value: Union[FRect, Rect]) -> None: ...
5454
@property
5555
def layer(self) -> int: ...
5656
@layer.setter

src_py/sprite.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@
8585
# specialized cases.
8686

8787
import types
88-
from typing import Optional
88+
from typing import Union
8989
from warnings import warn
9090

9191
import pygame
9292
from pygame.mask import from_surface
93-
from pygame.rect import Rect
93+
from pygame.rect import FRect, Rect
94+
from pygame.surface import Surface
9495
from pygame.time import get_ticks
9596

9697

@@ -109,29 +110,14 @@ class Sprite:
109110
110111
"""
111112

113+
image: Surface
114+
rect: Union[Rect, FRect]
115+
112116
def __init__(self, *groups):
113117
self.__g = {} # The groups the sprite is in
114-
self.__image: Optional[pygame.surface.Surface] = None
115-
self.__rect: Optional[pygame.rect.Rect] = None
116118
if groups:
117119
self.add(*groups)
118120

119-
@property
120-
def image(self):
121-
return self.__image
122-
123-
@image.setter
124-
def image(self, value: Optional[pygame.surface.Surface]):
125-
self.__image = value
126-
127-
@property
128-
def rect(self):
129-
return self.__rect
130-
131-
@rect.setter
132-
def rect(self, value: Optional[pygame.rect.Rect]):
133-
self.__rect = value
134-
135121
def add(self, *groups):
136122
"""add the sprite to groups
137123

0 commit comments

Comments
 (0)