Skip to content

Detect unused function variables inside functions #313

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

Closed
asottile opened this issue Apr 3, 2021 · 3 comments
Closed

Detect unused function variables inside functions #313

asottile opened this issue Apr 3, 2021 · 3 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @adamchainz on Oct 24, 2019, 04:18

Please describe how you installed Flake8

pip install flake8==3.7.8

Please provide the exact, unmodified output of flake8 --bug-report

{
  "dependencies": [
    {
      "dependency": "entrypoints",
      "version": "0.3"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.7.4",
    "system": "Darwin"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.5.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.1.1"
    }
  ],
  "version": "3.7.8"
}

Please describe the problem or feature

This code raises F841:

def foo():
    bar = 1

Python also lets us define variables as functions with the def statement, therefore I'd expect this to also raise F841:

def foo():
    def bar():
        pass

The real world case for this is I had a student create some unit tests that "passed" due to bad indentation, creating the test functions within setUp:

class MyTests(TestCase):
    def setUp(self):
        self.thing = Thing()
        
        def test_thing_1(self):
            self.assertEqual(self.thing.foo, "foo")

instead of

class MyTests(TestCase):
    def setUp(self):
        self.thing = Thing()
        
    def test_thing_1(self):
        self.assertEqual(self.thing.foo, "foo")

A flake8 warning would have helped them find the tests weren't being run.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Oct 24, 2019, 06:58

flake8 itself is just a framework and does not implement any checks of its own. you're probably looking for pyflakes which implements the F codes (on phone sorry, there's a duplicate issue there, I opened it in the past)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Oct 24, 2019, 06:58

closed

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @adamchainz on Oct 24, 2019, 23:56

Ah yes, sorry I forgot. The issue is here: PyCQA/pyflakes#392

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

No branches or pull requests

1 participant