Closed JaskRendix closed 1 year ago
Hi! I didn't know about mypy
and found dozens of errors. However, most are related to Optional[...]. For example, there are around 50 issues like "None YYY doesn't have XXX method...."
in methods that should not executed if the YYY variable is None; thus, most belong to static analysis issues.
I'll try to solve all (I pushed a new commit a few hours ago) in the next few days.
I think that static analysis does not work very well. In the case you provided, menu.add.label
returns a list of labels if max_char
is enabled; thus, translate and rotate are not defined.
I've reviewed dozens of mypy
issues, and most are invalid. I'm open to any PR addressing more "issues," but this is towards sanitizing mypy rather than improving the menu typing. For example, mypy says that baseimage has the following errors at line 880:
...
pygame_menu\baseimage.py:838: error: Item "None" of "Optional[Rect]" has no attribute "width" [union-attr]
pygame_menu\baseimage.py:838: error: Item "None" of "Optional[Rect]" has no attribute "height" [union-attr]
pygame_menu\baseimage.py:839: error: Item "None" of "Optional[Rect]" has no attribute "width" [union-attr]
pygame_menu\baseimage.py:839: error: Item "None" of "Optional[Rect]" has no attribute "height" [union-attr]
pygame_menu\baseimage.py:850: error: Item "None" of "Optional[Rect]" has no attribute "width" [union-attr]
pygame_menu\baseimage.py:865: error: Item "None" of "Optional[Rect]" has no attribute "height" [union-attr]
pygame_menu\baseimage.py:880: error: Item "None" of "Optional[Rect]" has no attribute "width" [union-attr]
pygame_menu\baseimage.py:881: error: Item "None" of "Optional[Rect]" has no attribute "height" [union-attr]
pygame_menu\baseimage.py:896: error: Item "None" of "Optional[Rect]" has no attribute "width" [union-attr]
pygame_menu\baseimage.py:896: error: Item "None" of "Optional[Rect]" has no attribute "height" [union-attr]
...
However, within baseimage.draw the "if area is None" is already addressed; thus, these mypy
issues are not valid.
For these reasons, I will close this issue for now. Anyone with typing improvements can create as many PRs as they want. Thanks!
Hello, there!
I was running
mypy
to check for typehints (spring cleaning) and it flagged me the labels (with .translate) -> no issues with buttons and images.Out of curiosity I tried to run
mypy
on this file: https://github.com/ppizarror/pygame-menu/blob/master/pygame_menu/examples/other/widget_positioning.pythe output with pygame_menu 4.3.8:
that's the exact output I get on my repository.