ruff
ruff copied to clipboard
Allow noqa on preceding line
Would it be possible to place the ignore comment on the preceding line? Something like:
def to_exp(self) -> VonMisesFisherEP:
q = self.mean_times_concentration
kappa: RealArray = jnp.linalg.norm(q, 2, axis=-1, keepdims=True)
# noqa: PLR2004
return VonMisesFisherEP(jnp.where(kappa == 0.0, q, q * (_a_k(d, kappa) / kappa)))
in addition to
def to_exp(self) -> VonMisesFisherEP:
q = self.mean_times_concentration
kappa: RealArray = jnp.linalg.norm(q, 2, axis=-1, keepdims=True)
return VonMisesFisherEP(
jnp.where(kappa == 0.0, # noqa: PLR2004
q,
q * (_a_k(d, kappa) / kappa)))
The latter sometimes requires breaking long lines of code in unnatural places. The simple rule would be if noqa
occurs on a line without any code, then it applies to the next line that has code in it.
This will be even more useful if human-friend rule names https://github.com/charliermarsh/ruff/issues/1773 are implemented since then the rule names will be longer, breaking even more lines of code.
For reference, pylint
has a disable-next
directive, which accomplishes this nicely.
So similarly, there could be # noqa-next
.
noqa-next
is a cool idea. If we're going down that road, you could also have:
-
noqa-file
: At the top of a file to indicate blocking the whole file. -
noqa-block
: At the start of a block to indicate that it's for the entire block (function, if, while, etc.)
I think if/when we go this route we'd use directives similar to the Rust ecosystem.
@zanieb What are those like?