
I happen to give a talk just yesterday that was about pretty much this ( https://github.com/DavidMertz/PythonRuntimeTyping; hopefully PyCon MEA publishes video after a bit). I illustrate checking the same program using mypy, pytype, and pyright. There is a lot of overlap in what they flag as problems, but indeed there are significant differences. However, the differences are because of different GOALS in the programs. For example, mypy very explicitly only pays attention to code that is explicitly annotated. Pytype performs actual type inference as well, and sometimes identifies problems even in completely non-annotated code; at the same time, pytype deliberately ignores things that are "wrong" but that will not affect runtime behavior. Pyright is the most "aggressive" of these tools (I haven't really played with pyre) but that is exactly appropriate because the tool is mostly used as a plugin to VS Code (maybe other editors), where the cost of a false positive complaint is small, and the cost of a false negative is more important. All three of these tools serve a reasonable, but different purpose. Of course they overlap to a large degree, but it would be bad to declare that only one of these purposes was "legitimate." On Fri, Oct 14, 2022 at 4:38 AM Christopher Barker <pythonchb@gmail.com> wrote:
Static type analysis is still experimental in Python.
Evidence for this is that there ARE multiple type checkers, and they don’t all behave the same way.
It really needs to settle down before there is a single “official” type checker.
Also: Static type checking is optional in Python. There are those of us that are not convinced that static type checking is or should be a Python best practice. An official type checker would be an endorsement not just of that particular approach to type checking, but also the concept itself — I don’t think the community is ready for that.
-CHB
On Thu, Oct 13, 2022 at 9:23 AM <pvmpatch@163.com> wrote:
I’m doing some research on Python type annotations recently. I found that, some dynamic typing related bugs can be effectively avoided in the early stages of code development, by adding type annotations to Python code and applying some type checking tools (such as MyPy, PyType, Pyright, and Pyre, etc.). The introduction of type annotations effectively improves the type safety of Python code.
However, different tools discover, classify and report defects in different ways, and there is little overlap in the defects they reported. In the same code segment, some type checking tools will report defects but some will not. These may confuse users. Because it is not easy for the user to determine which tools give credible results.
Based on the above, I have the following suggestion: Is it possible that Python provide a new type checker officially? Or is it possible that Python choose one of the off-the-shelf type checking tools as the official and recommended one?
Python is my favourite programming language. I sincerely hope that I can help Python become stronger and safer. I hope this idea can be useful for you. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CG2IGZ... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD (Chris)
Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/UFEWUO... Code of Conduct: http://python.org/psf/codeofconduct/
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.