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

unused-variable false negative in functions with Raise #3028

Closed
DavidDupre opened this issue Jul 27, 2019 · 1 comment
Closed

unused-variable false negative in functions with Raise #3028

DavidDupre opened this issue Jul 27, 2019 · 1 comment
Labels

Comments

@DavidDupre
Copy link

Steps to reproduce

  1. Create a file like this:

    def hello(arg):
        my_var = 'something'
        if arg:
            return True
        raise Exception
  2. python3 -m pylint test.py

Current behavior

$ python3 -m pylint test.py
************* Module test
test.py:1:0: C0111: Missing module docstring (missing-docstring)
test.py:1:0: C0111: Missing function docstring (missing-docstring)

------------------------------------------------------------------
Your code has been rated at 6.00/10 (previous run: 4.00/10, +2.00)

Expected behavior

I expected "unused-variable" for my_var. This did come up for pylint 1.8.3.

pylint --version output

$ python3 -m pylint --version
__main__.py 2.3.1
astroid 2.2.5
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]

My thoughts

I think this is a bug in checkers.utils.is_error. The docstring claims to "return true if the function does nothing but raising an exception", but it doesn't catch cases like this where the function may return early. This causes VariablesChecker.leave_functiondef to skip checking for unused variables.

@PCManticore
Copy link
Contributor

Thanks for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants