Pylance error: "topleft" is not a known attribute of "None"
12:35 21 Dec 2025

I created a class that inherits from the pygame.sprite.Sprite class. In the init() method i create a rect and set its position. I have another method(set_pos()) where i also set the position of the rect.

The code works without runtime errors, but i get this pylance error: "topleft" is not a known attribute of "None" for the method set_pos().

When i create the class without inheriting from pygame.sprite.Sprite i dont get this error.

import pygame as pg


class Tile(pg.sprite.Sprite):

    def __init__(self, image, pos):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect()
        self.rect.topleft = pos

    def set_pos(self, pos):
        self.rect.topleft = pos

I am using this Pylance version: 2025.10.4, this Pygame version: 2.6.1 and this Python version: 3.12.1

python pygame pylance