flake8's "# noqa" interferes with markdown using mkdocstrings

Question:

I am using mkdocstrings in order automatically generate an API documentation from my Python functions. At the same time I am using flake8 to keep my code in good shape.

If you want to ignore some flake8 warnings on an in-line basis, you could insert "# noqa" whereby the following lines of code will be ignored by flake8.

That’s nice, however, "# noqa" will be interpreted by mkdocstrings as a markdown header.

Now, I am wondering how to resolve that conflict between flake8 and mkdocstrings?

Asked By: Andi

||

Answers:

put the noqa comment on the end of the docstring — it will apply to any line within the docstring without changing the string’s contents (note: you need a sufficiently new flake8, this change is relatively recent (probably >=4.x))

def f():
    """some docstring here

    something which causes a warning
    """  # noqa: ABC123

disclaimer: I am the current flake8 maintainer

Answered By: Anthony Sottile
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.