Imports and methods fall in the same namespace?
Bug #1675659 reported by
Lele Gaifax
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Pyflakes |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
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()
To post a comment you must log in.
The error seems correct to me. If you had
import bar
class Foo:
a = bar
then Foo().a would be bar (the module). If you had
class Foo:
def bar(self):
pass
a = bar
then Foo().a would be bar (the method). So the method does override the imported name in the class namespace, which pyflakes warns about (but only if the name is unused, to avoid false positives).