Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spell-checker crashes if a regex('^ +#') line in a docstring contains a typo #3786

Closed
gschaffner opened this issue Aug 23, 2020 · 0 comments · Fixed by #3787
Closed

Spell-checker crashes if a regex('^ +#') line in a docstring contains a typo #3786

gschaffner opened this issue Aug 23, 2020 · 0 comments · Fixed by #3787
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash

Comments

@gschaffner
Copy link
Contributor

Steps to reproduce

  1. pip install pyenchant
  2. Create the file test.py with contents
    def foo():
        """
        # tpyo
        """
  3. pylint --disable all --enable spelling --spelling-dict en_US test.py

Current behavior

Traceback (most recent call last):
  File "/home/ganden/.pyenv/versions/jlab-test/bin/pylint", line 10, in <module>
    sys.exit(run_pylint())
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/lint/run.py", line 349, in __init__
    linter.check(args)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 862, in check
    self._check_files(
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 896, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 922, in _check_file
    check_astroid_module(ast_node)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1054, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/checkers/spelling.py", line 397, in visit_functiondef
    self._check_docstring(node)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/checkers/spelling.py", line 411, in _check_docstring
    self._check_spelling("wrong-spelling-in-docstring", line, start_line + idx)
  File "/home/ganden/.pyenv/versions/3.8.3/envs/jlab-test/lib/python3.8/site-packages/pylint/checkers/spelling.py", line 347, in _check_spelling
    col = line_segment.index(word)
ValueError: substring not found

Expected behavior

Find tpyo correctly.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.3 (default, Jul 24 2020, 19:51:30)
[GCC 10.1.0]
# and also
pyenchant 3.1.1
enchant 2.2.8
nuspell 3.1.2

More info

The following do not crash pylint (they behave as expected):

def foo():
    """# tpyo"""
"""# tpyo"""
def foo():
    """
# tpyo
    """
def foo():
    """
    # cat
    """
def foo():
    """
    tpyo # cat
    """
def foo():
    """
    cat # tpyo
    """
@gschaffner gschaffner mentioned this issue Aug 23, 2020
4 tasks
@AWhetter AWhetter added Bug 🪲 Crash 💥 A bug that makes pylint crash labels Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants