pylint inline comments wrapped to wrong line
See original GitHub issuePylint inline comments on wrong line after wrapping long line.
Inline comments that trail a command continue to trail the command after black wraps a long line onto multiple lines. While seemingly consistent with the original form, this makes inline comments like #pylint: disable=invalid-name ineffective since they are not on the first line of the command. For example:
asdf = namedtuple('nameoftuplegoeshere', 'fieldsgohere andnoather andanother morehere') # pylint: disadble=invalid-name
becomes
asdf = namedtuple(
"nameoftuplegoeshere", "fieldsgohere andnoather andanother morehere"
) # pylint: disadble=invalid-name
For pylint to work properly, it needs to be:
asdf = namedtuple( # pylint: disadble=invalid-name
"nameoftuplegoeshere", "fieldsgohere andnoather andanother morehere"
)
Since the #pylint comment is no longer on the same line as asdf =
it does not suppress the pylint warning, changing the behavior of the comment.
While not technically a bug, and not changing the functionality of the code, it does have an undesirable effect. Is there some philosophy I’m missing, or is there a recommendation for how to handle this?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:9 (3 by maintainers)
just an alternative, make it configurable to prevent formatting on lines with pylint definitions on them?
@yilei
open-paren
seems to make sense to me. There are many cases where this won’t work as many linting errors are raised onast
nodes somewhere in the middle of line, but it is definitely an improvement over putting them at the end of the line.I was wondering though, if you are indeed going to special case
pylint
would you consider creating a# pylint: disable-next:
comment on the line above the original line? This option was released with https://github.com/PyCQA/pylint/pull/4797 inpylint
2.10
on2021-08-21
. So over a year ago. According to PePy the largest part of our downloads are indeed2.10+
. I think in general, disabling withdisable-next
will cover more cases than placing on the opening parenthesis. Feel free to disregard this if you don’t want to include such a version dependent feature or if this is too much extra work to support an external project (I can also help with implementing this with some guidance on the codebase). I just thought I would present it as an alternative.Thanks again for the thorough investigation and getting back to us in our own repo. Much appreciated!
@Pierre-Sassoulas Tagging you as you might be interested in this issue