Ruff Ignore Inline or Function Rule Check

1.8k Views Asked by At

I am using ruff==0.0.265 I have a single function I expect to have complexity and do not wish to change that.

src/exceptions.py:109:5: C901 `convert_py4j_exception` is too complex (11 > 10)
src/exceptions.py:109:5: PLR0911 Too many return statements (10 > 6)

How do I ignore a specific rule with ruff on a single function convert_py4j_exception(). I do not want to turn it off completly.

1

There are 1 best solutions below

1
On

You can add an ignore comment at the end of a line. In this case I would assume it has to be added on the def line. The ruff error does indicate what line is meant though. (109 in your case)

So for example you could do:

def convert_py4j_exception():  # noqa: C901 PLR0911
    ...

In general you should avoid disabling linting rules and try to refactor your code instead.

I have to do it so rarely, that I always need to look it up :-D Hopefully next time I will find my answer here.