Is there any *good* type-checker for python? But I really mean a good one... I had bad experiences with mypy being not smart enough and even pyre-check can't handle `Optional` types correctly (similar issue with mypy).
Should I just give up on trying to have a better experience with python and just accept the fact that it is an inherently bad language to type-check?
#python #mypy #pyre #typechecker #typehints
Yesterday mypy forced me to learn about covariance, contravariance (and by extension invariance) in the context of programming language typing which isn't exactly what I signed up for, but it's hard to complain about learning new things so ¯\_(ツ)_/¯
#python #mypy #computerscience #programming
No więc dzisiaj aktualizuję #mypy do 1.5.1, i widzę, że nie ma żadnych zmian w kodzie, tylko zmiana numeru wersji. Mały CDF (co do faki?).
Teraz ztrawhcse gada mi na IRC-u, że przecież zmiany są:
https://github.com/python/mypy/compare/v1.5.0...v1.5.1
ja na to: no tak, czyżby nadpisali tag? Więc wymuszam ponowne pobranie, ale suma kontrolna się zgadza. Coraz większe CDF. Pobieram przez przeglądarkę, dostaję ten sam plik.
Wtedy ściągam 1.5.0… i mamy facepalm miesiąca. Nadpisali 1.5.0 na wcześniejszą wersję kodu już po tym, jak zaktualizowaliśmy paczkę w Gentoo.
Innymi słowy, użytkownicy Gentoo właściwie używali 1.5.1 już od tygodnia. Nie musicie nam dziękować.
Asking for specific #examples type checking finds is ... unproductive. You write 2 modules of code, run #mypy, and get a list of the 11 places you need to fix - before you've even written unit tests that may or may not have caught the same problem.
If I tried to keep track of them all, I wouldn't have time to write code.
[...]
#examples #mypy #typehints #typechecking #tests #lint
@EMR @astraluma I know a few tools!
https://github.com/typeddjango/awesome-python-typing#testing
The difference in these tools is where you want to put your type tests: next to regular tests, in yaml, or in a separate Python file(s). The first approach is bad if you don't want to exclude all your tests from type checker. The second one is fine but you lose autocomplete and linters. I'm the author of the third way:
https://github.com/orsinium-labs/mypy-test
Also, basic tests are possible with just #mypy:
@ambv so, what do you think about this problem?
It also behaves the same way in mypy. But here bug is not closed, and i'm hoping it can be fixed.
#pyright #mypy #pythontyping #Python
#Python #PythonTyping #Pyright #Pylance #Mypy
Is there a way to create type stub only for part of the library?
For example: I want to include types for a single object, but don't want to maintain full copy of the library.
https://github.com/carltongibson/django-filter/pull/1585/files
#mypy #pylance #pyright #pythontyping #Python
@python_discussions That's not true. You need to specify `__all__` in `__init__.py` (and other facades) so that #mypy, #flake8, and #ruff know that these packages are imported to be exported. Then flake8 and ruff won't report unused import and mypy will allow reexports from the module.
@glowrocks That's great! I'm glad to hear it empowers you to achieve your goals.
If you need guidance on more classic and reliable tools, just ask. In #python, I recommend to have a look at #ruff and #mypy, if you haven't already. These are good for finding simple errors without running the code. And Deal and Hypothesis should help with generating tests.
@benc mypy will report it by default, unless the name you are trying to import is aliased in the proxy module using `as` or included in `__all__`:
https://mypy.readthedocs.io/en/stable/config_file.html#confval-implicit_reexport
Edit: reading the docs again, I see that reexport is allowed by default, you have to explicitly forbid it in the mypy config.
Just saw that there is now an official VSCode extension from Microsoft for using mypy.
https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker
Very cool!
Anyone out there having to support more than one version of MyPy|TypeShed|mypy-extensions|python with the same codebase?
Even with having different .mypy.ini's sometimes the hints in the code are incompatable and you end up playing whack a mole.
For example, is it r: Redis or r: Redis[bytes] or Redis[str]?
#TIL executing #mypy as a daemon with an sqlite cache makes it go really fast. Squashed a lot of type errors with that workflow.
https://mypy.readthedocs.io/en/stable/mypy_daemon.html
https://mypy.readthedocs.io/en/stable/additional_features.html#caching-with-mypy-daemon
dmypy run -- --sqlite-cache --use-fine-grained-cache <path>
dmypy check <path>
📢 Announcing v3.0.0 of our #github reusable #workflows
https://github.com/coatl-dev/workflows/tree/v3.0.0
#github #black #flake8 #pylint #mypy #python2 #python #nox #tox #precommit
#github #workflows #black #flake8 #pylint #mypy #python2 #python #nox #tox #precommit
Is there a common way to typehint slice? Especially for cases, when you want specific things like label-based slicing (think Pandas `.loc` for a string index). Pandas does not have any typehints for keys afaik. #pandas #python #datascience #mypy
#pandas #Python #DataScience #mypy