Today I was converting yet another repository from black and flake8 to ruff (which reminds me, I really need to write up a guide for that).

I had the following line of python code which I wanted to keep as-is:

...
# It's a common pattern in Django settings to import
# everything from a "local.py" file at the end.
from .local import *

Mypy complains about this, because you should never import *. So let's tell it to ignore that with the # type: ignore comment.

...
from .local import *  # type: ignore

However, now ruff is wanting move that line to the top of the file (which is a rule I normally want, just not in this case). So I can add the # noqa comment.

...
from .local import *  # noqa

This works great for ruff, but now I am having trouble with mypy! I need to somehow add both.

The Solution

Through trial and error, I've discovered that you can in fact add both, but they need to be in a particular order for the tools to parse them.

"type: ignore" must come first, followed by "noqa". Each has the # comment prefix with two spaces before it.

...
from .local import *  # type: ignore  # noqa

I'm sure this works only due to a bug or side effect of how each tool processes comments. I would love to see more cooperation from the tool makers - or perhaps an officially-unofficial set of comments which all tools will ignore.