kitao / pyxel

A retro game engine for Python
MIT License
15.31k stars 847 forks source link

mypy thinks Image and Tilemap have no methods #494

Closed AlexMax closed 11 months ago

AlexMax commented 1 year ago

When running mypy --strict on my pyxel project, I am getting the following error messages:

ichor\world\level.py:89: error: "Tilemap" has no attribute "set"  [attr-defined]   
ichor\world\world.py:26: error: "Tilemap" has no attribute "image"  [attr-defined] 
ichor\game.py:18: error: "Image" has no attribute "load"  [attr-defined]
ichor\game.py:19: error: "Image" has no attribute "load"  [attr-defined]
ichor\game.py:20: error: "Image" has no attribute "load"  [attr-defined]

Upon inspection, it looks like there is a part of __init__.pyi that defines Image and Tilemap as a sort of forward declaration:

# Graphics
class Image: ...
class Tilemap: ...

If I delete the forward declarations and move the correct definitions from later in the file to where these forward declarations were, mypy can now find the methods on the class just fine.

I am running Python 3.11.5 with the following requirements.txt:

mypy==1.5.1
mypy-extensions==1.0.0
pyxel==1.9.18
typing_extensions==4.7.1
kitao commented 11 months ago

Thank you for the information. The declaration order will be changed in Pyxel 2.0.2.