Skip to content

Commit 6ec4728

Browse files
committed
checks and quality pass
1 parent 41cb285 commit 6ec4728

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

buildconfig/stubs/pygame/sprite.pyi

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ class DirtySprite(Sprite, _SupportsDirtySprite):
118118
def _set_visible(self, val: int) -> None: ...
119119
def _get_visible(self) -> int: ...
120120

121-
# typevar bound to Sprite, _SupportsSprite Protocol ensures sprite
121+
# covariant typevar bound to Sprite, _SupportsSprite Protocol ensures sprite
122122
# subclass passed to group has image and rect attributes
123-
_TSprite = TypeVar("_TSprite", bound=_SupportsSprite)
123+
# covariant is required for _Group to work with any AbstractGroup
124+
# otherwise Sprite.add/remove do not accept AbstractGroup as arguments
124125
_TSprite_co = TypeVar("_TSprite_co", bound=_SupportsSprite, covariant=True)
125-
_TSprite2 = TypeVar("_TSprite2", bound=_SupportsSprite)
126-
127-
# almost the same as _TSprite but bound to DirtySprite
128-
_TDirtySprite_co = TypeVar("_TDirtySprite_co", bound=_SupportsDirtySprite, covariant=True)
126+
_TDirtySprite_co = TypeVar(
127+
"_TDirtySprite_co", bound=_SupportsDirtySprite, covariant=True
128+
)
129129

130130
# typevar for sprite or iterable of sprites, used in Group init, add and remove
131131
_SpriteOrIterable = Union[_TSprite_co, Iterable[_SpriteOrIterable[_TSprite_co]]]
@@ -210,9 +210,9 @@ class LayeredDirty(LayeredUpdates[_TDirtySprite_co]):
210210
)
211211
def set_timing_treshold(self, time_ms: SupportsFloat) -> None: ...
212212

213-
class GroupSingle(AbstractGroup[_TSprite]):
214-
sprite: _TSprite
215-
def __init__(self, sprite: Optional[_TSprite] = None) -> None: ...
213+
class GroupSingle(AbstractGroup[_TSprite_co]):
214+
sprite: _TSprite_co
215+
def __init__(self, sprite: Optional[_TSprite_co] = None) -> None: ...
216216

217217
# argument to collide_rect must have rect attribute
218218
def collide_rect(left: _HasRect, right: _HasRect) -> bool: ...
@@ -244,7 +244,9 @@ def collide_mask(
244244
left: _SupportsCollideMask, right: _SupportsCollideMask
245245
) -> Optional[tuple[int, int]]: ...
246246

247-
# generic for _HasRect, used in sprite collide functions
247+
# typevars for sprite collide functions
248+
_TSprite = TypeVar("_TSprite", bound=_SupportsSprite)
249+
_TSprite2 = TypeVar("_TSprite2", bound=_SupportsSprite)
248250
_THasRect = TypeVar("_THasRect", bound=_HasRect)
249251

250252
def spritecollide(

0 commit comments

Comments
 (0)