question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pylint inline comments wrapped to wrong line

See original GitHub issue

Pylint 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:open
  • Created 2 years ago
  • Reactions:5
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
unitysipucommented, Feb 4, 2022

just an alternative, make it configurable to prevent formatting on lines with pylint definitions on them?

1reaction
DanielNoordcommented, Aug 31, 2022

@yilei open-paren seems to make sense to me. There are many cases where this won’t work as many linting errors are raised on ast 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 in pylint 2.10 on 2021-08-21. So over a year ago. According to PePy the largest part of our downloads are indeed 2.10+. I think in general, disabling with disable-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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pylint features - Pylint 2.16.0-dev documentation
Unexpected line ending format. There is '%s' while it should be '%s'. Used when there is different newline than expected. superfluous-parens (C0325).
Read more >
Is it possible to ignore one single specific line with Pylint?
This way you can ignore a single error on a single line without having to disable checking that error in the whole file....
Read more >
textwrap — Text wrapping and filling — Python 3.11.1 ...
Wraps the single paragraph in text (a string) so every line is at most width characters long. Returns a list of output lines,...
Read more >
The Black code style - Black 22.12.0 documentation
How Black wraps lines#. Black ignores previous formatting and applies uniform horizontal and vertical whitespace to your code. The rules for horizontal ...
Read more >
Using Pylint to Improve the Quality of Your Code - TurboGears
pylint also allows you to modify it's global presets from a configuration file in your home directory. However, the preferred method is to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found