jorio / gitfourchette

The comfortable Git UI for Linux
https://gitfourchette.org
GNU General Public License v3.0
16 stars 2 forks source link

Type checking #2

Open CoolCat467 opened 1 day ago

CoolCat467 commented 1 day ago

I noticed that running mypy (https://github.com/python/mypy) on this project shows a bunch of type errors, and I was wondering if you would be interested in accepting a pull request wherein I add type annotations/fix type issues in this project.

Checking your code with a static type analyzer like mypy can help catch potential runtime issues before they happen. A common parallel I have heard is that type checkers are like linters (such as ruff) on steroids.

Additionally, adding typing information can help other developers (or yourself) understand your code and what types of data should be where. It also opens the door to potentially using mypyc on this project, meaning code could be compiled into c-based modules that can in some cases run significantly more efficiently, but that would be something for later.

jorio commented 14 hours ago

Thank you for the offer! Unfortunately, it looks like mypy isn't very usable with PyQt6 (and I couldn't get it to recognize the types for PySide6, the other Qt binding library).

For instance, it complains that the None part is ignored in many QSomeType | None unions that abound in PyQt6's type stubs (alternatively written as Optional[QSometype]). I suspect these stubs were automatically generated with the assumption that whenever a C++ function in Qt takes or returns a pointer, it can technically be NULL, so this should auto-translate to | None; but this is impractical for writing GUI code in Python.

There are surely inaccuracies in this project's type annotations, but I'd prefer to fix them on a case-by-case basis, rather than adding a lot of boilerplate at once to comply with mypy's enforcement of PyQt6's auto-generated type annotations. Until then, thorough test coverage is our main tool for ironing out runtime issues.