PyCQA / PyCQA/pyflakes

Imports and methods fall in the same namespace?

Open
#268 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.5k
Forks
190
Avg merge
8m
Merged PRs (30d)
13

Description

Original report by lelegaifax on Launchpad:


Consider the following script:

import bar

class Foo:
    def bar(self):
        pass

Pyflakes emits:

$ pyflakes foo.py 
foo.py:1: 'bar' imported but unused
foo.py:4: redefinition of unused 'bar' from line 1

Both disappears if bar is actually used, so the following is clean:

import bar

class Foo:
    def bar(self):
        pass

coffee = bar.Espresso()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the Python script in foo.py and the pyflakes command shown. Compare the diagnostics for the unused import and the class method, then inspect the relevant analysis path to determine how these names are scoped. Done means the reported script no longer produces a false redefinition warning while genuine unused-import diagnostics remain accurate.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.