Skip to content
New issue

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

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

Already on GitHub? # to your account

Pylint similarities checker fails with "ignore-signatures" option enabled and function with docstring-only body #4648

Closed
mhumetskyi opened this issue Jul 1, 2021 · 6 comments · Fixed by #4649
Assignees
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash
Milestone

Comments

@mhumetskyi
Copy link
Contributor

Newly introduced ignore-signatures option for similarities checker fails for functions with an empty body with docstring only.
Works fine if ignore-signatures is disabled.

Steps to reproduce

Given a file a.py:

def example():
    """Valid function definition with docstring only."""

Current behavior

Result of pylint --disable=all --enable=similarities --ignore-signatures=yes a.py:

Traceback (most recent call last):
  File "/Users/user/venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 973, in check
    self._check_files(
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1211, in _check_astroid_module
    checker.process_module(ast_node)
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/checkers/similar.py", line 444, in process_module
    self.append_stream(self.linter.current_name, stream, node.file_encoding)
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/checkers/similar.py", line 77, in append_stream
    LineSet(
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/checkers/similar.py", line 269, in __init__
    self._stripped_lines = stripped_lines(
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/checkers/similar.py", line 221, in stripped_lines
    chain(*(range(func.fromlineno, func.body[0].lineno) for func in functions))
  File "/Users/user/venv/lib/python3.8/site-packages/pylint/checkers/similar.py", line 221, in <genexpr>
    chain(*(range(func.fromlineno, func.body[0].lineno) for func in functions))
IndexError: list index out of range

Expected behavior

Pylint shouldn't fail, no error appears.

pylint --version output

Result of pylint --version output:

pylint 2.9.2
astroid 2.6.2
Python 3.8.2 (default, Jun  8 2021, 11:59:35) 
[Clang 12.0.5 (clang-1205.0.22.11)]
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue, and for all the detail provided, it will be fixed in 2.9.3.

@mhumetskyi
Copy link
Contributor Author

mhumetskyi commented Jul 1, 2021

@Pierre-Sassoulas thanks for the quick response.

The way it was resolved in #4649 we will ignore such functions at all and signatures would be checked in similarities for them.

Should we have a follow-up issue to improve it?

@Pierre-Sassoulas
Copy link
Member

Yes, I just wanted to avoid the crash in 2.9.3. Would you be interested in doing the real fix 😄 ?

@mhumetskyi
Copy link
Contributor Author

@Pierre-Sassoulas yes 🙃

Additionally, we could try to improve ignore-signatures option to also ignore class methods signatures as well, because currently, it doesn't. Only functions signatures are ignored.

But possibly it could be another improvement issue.
Could I create both of them?

@Pierre-Sassoulas
Copy link
Member

Sound great ! Fixing the false negative can go in 2.9, but we'll wait for 2.10 to merge the "ignore class methods signatures" :)

@mhumetskyi
Copy link
Contributor Author

Created both issues I have mentioned: #4652, #4653.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash
Projects
None yet
2 participants