pylint
pylint copied to clipboard
# pylint: disable=wrong-spelling-in-comment does not work
Steps to reproduce
-
Create test.py
""" This is a test file """ print "Hello World" # pylint: disable=wrong-spelling-in-comment # I probably have some mipeled words -
run pylint
$ pylint test --spelling-dict=en_US
Current behavior
I: 5, 0: Locally disabling wrong-spelling-in-comment (C0401) (locally-disabled)
C: 6, 0: Wrong spelling of a word 'mipeled' in a comment:
# I probably have some mipeled words
Expected behavior
I: 5, 0: Locally disabling wrong-spelling-in-comment (C0401) (locally-disabled)
pylint --version output
No config file found, using default configuration
pylint 1.5.5,
astroid 1.4.5
Python 2.7.11 (default, Mar 31 2016, 20:46:51)
[GCC 5.3.1 20151207 (Red Hat 5.3.1-2)]
This is important because I could have blocks of commented code that should not be spellchecked
I did take a look why this is happening. While I won't have time to work on it until 2.0 is released, I will leave some notes in the case someone wants to pick it up until then.
What happens now is that for analyzing comments, we are relying on tokenizing the module being analyzed, looking for pragma disables and storing the states in some hash maps (https://github.com/PyCQA/pylint/blob/master/pylint/lint.py#L621). Next, we will compute the block states, using collect_block_lines (https://github.com/PyCQA/pylint/blob/master/pylint/utils.py#L504). Now, this method does an interesting thing, which is to clear the previously computed states in order to recompute it according to each node's logic. The problem now is that what we computed before was for a comment, which is not actually part of the AST. In this particular situation, since the comments are being stripped from the AST, the Module node will have the first and the last offsets as 0, respectively 2, while the comment disable was for line number 3, which will result in the line being skipped with this check https://github.com/PyCQA/pylint/blob/master/pylint/utils.py#L544.
Obviously, having the comments in the AST is the best solution we could have at this point, but I'm afraid it is out of the question for the following months. The next thing we could do is to try to preserve the state for comments, but this will need some modifications in the hash maps we are using for the file states.
Thanks for looking into it. Based on what you said it sounded like a workaround would be to add some code to the end of the module in order to extend the AST. This behaved as expected.
"""
This is a test file
"""
print "Hello World"
# pylint: disable=wrong-spelling-in-comment
# I probably have some mipeled words
pass # pylint: disable=unnecessary-pass
I: 5, 0: Locally disabling wrong-spelling-in-comment (C0401) (locally-disabled)
I: 7, 0: Locally disabling unnecessary-pass (W0107) (locally-disabled)
It's not ideal, but it's better than having to disable spellchecking completely.
Yeah, this could be a fix for now, until we will have a proper one for pylint.