lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.36k stars 666 forks source link

Add type hints #207

Closed septatrix closed 2 years ago

septatrix commented 3 years ago

This would allow other developers to check their code using mypy if they use this library. Preferably this would be done using type annotations inside the code itself so this library could also profit from it.

This should be done after dropping 2.7 support so the annotations do not need to be inside comments (#206). Maybe this could also be done after dropping 3.5 support (EOL last september) so variables could also be annotated and not only functions.

heuer commented 3 years ago

May I suggest a 3rd alternative:Use stub files

I use them to keep support for 2.7 and >= 3.5 for the public API.

Example: https://github.com/heuer/segno/blob/master/segno/__init__.pyi

I don't know how important Python 2 compatibility is to this project but it may help to support Py2 and Py3 compatibility without cluttering the code with type hint comments.

SmileyChris commented 2 years ago

Could do some more, but I've started adding type hints. mypy qrcode --ignore-missing-imports passes.

If someone wants to create a PR for more complete typing, that's cool. But I'll close this issue for now.