I have a simple Entity class which inherits from pygame.sprite.Sprite
like so:
import pygame
class Entity(pygame.sprite.Sprite):
def __init__(
self,
pos: tuple[int, int],
size: tuple[int, int],
color: str,
*groups: pygame.sprite.AbstractGroup,
) -> None:
super().__init__(*groups)
self.velocity = pygame.Vector2((0, 0))
self.image = pygame.Surface(size)
self.rect = self.image.get_rect(topleft=pos)
self.image.fill(pygame.Color(color))
However, whenever I try to do something with the class's self.rect
, pyright emits the following errors:
Although the code still runs fine, I was wondering what is the cause of those error messages, and what can I do to prevent them from showing up?
I tried to do 'None checks' i.e. if self.rect is not None:...
on all the blocks emitting that error but I don't think that is a very good solution.
If it matters, I am using pyright on the native neovim LSP.
Any help would be much appreciated!