From the documentation on mccabe (which is used by flake8 under the hood):
To silence violations reported by
mccabe, place your# noqa: C901
on the function definition line, where the error is reported for
(possibly a decorator).
So you should put the # noqa comment on the line containing def or the line with a decorator.