Dear Friends,
I recently noticed a recurring pattern in Python develop toolchains that seems worth discussing:
Python tooling has accumulated a growing number of tiny, tool-specific DSLs hidden inside comments:
# pylint: ...
# mypy: ...
# pyright: ...
# noqa
# ruff: ...
# fmt: ...
# isort: ...
and many others.
Even Python itself has special comment-based syntax, such as type comments and # type: ignore[...], which are treated specially by the parser and AST.
These constructs are no longer really ordinary comments: they carry structured, machine-readable semantics. Yet every tool has to invent its own mini grammar and parsing rules for essentially the same purpose.
I wonder whether we could approach this in a unified way:
- Use a clear, dedicated syntax marker for all tool directives, instead of pseudo comment. May be some unoccupied operator in python syntax like “!” (exclaimation operator) is helpful? for example, to declare lint rules:
!pylint.disable("no-members", "unused-variable")
some_c_module.ide_cannot_resolve_symbols(...)
- Instead of letting every tool invent its own tiny DSL, let the directive payload use normal Python expression syntax. Just like the example that I took above.
Type comments have already gone through a process of standardization, eventually becomes type annotations. I wonder if these different comment DSLs invented by various tools could someday go through a similar process and become something standardized.