I agree that if we are designing the desirable future state to aim for, it’s much better for Python’s parser to have a mode where it simply preserves comments in general (mypy can use this mode and retain greater independence and flexibility in exactly what comment formats it supports) than for the parser to care about the content of those comments at all.
There’s also a group that met at PyCon to work on standardizing on a Python CST parser that preserves all syntactic trivia (comments and white space), for use by linters, formatters, refactoring tools, etc. LibCST already exists in this space and has a new experimental parser that supports 3.10+. One possible future is that Python’s built-in parser stops preserving or paying attention to comments at all, and mypy switches instead to a CST library like LibCST. But there is also some extra cost to whitespace parsing, which a type checker doesn’t need.
On Wed, Jun 8, 2022 at 3:07 PM Eric Traut email@example.com wrote:
Yes, mypy supports "# type: ignore[x, y, z]", but that's a problem for code bases that are using multiple type checkers.
PEP 484 documents "# type: ignore", but it says nothing about what comes after the comment. Mypy chose to support a non-standard extension where it modifies the behavior of "# type: ignore" if it is followed by a group of mypy-specific diagnostic names enclosed in square brackets. Other type checkers like pyright treat "# type: ignore" as it is documented in PEP 484 regardless of what comes after it.
Developers who want to run both mypy and other type checkers on their code need a way to specify "mypy should ignore these issues", "pyright should ignore these issues", etc. Mypy currently provides no way to do this. Pyright provides a pyright-specific "# pyright: ignore[x, y, z]". It would be good for mypy and other type checkers to do the same. But supporting this is difficult for mypy because it relies on the Python parser, which has intimate knowledge of "# type: ignore" comments.
-Eric _______________________________________________ Typing-sig mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: firstname.lastname@example.org