-
Notifications
You must be signed in to change notification settings - Fork 180
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
Imports and methods fall in the same namespace? #268
Comments
Original comment by asmeurer (@asmeurer?) on Launchpad: The error seems correct to me. If you had import bar
class Foo:
a = bar then class Foo:
def bar(self):
pass
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). |
Original comment by lelegaifax on Launchpad: Well, I don't agree with your argument, but if that's instead valid, then I would def a():
pass
class A:
def a(self):
pass should emit the same error instead of the current happy mood, and even a = 1
def b():
a = 2 should "warn" me about the override of a global symbol within the function namespace, In any case, the fact that the error "disappear" as soon as I use the imported symbol |
Original comment by bitglue (@bitglue?) on Launchpad: Report seems legit to me. In the example: import bar
class Foo:
def bar(self):
pass the bar import is unused, and there should remain an error about that. But defining a bar function inside the class scope does not seem like an error. Pyflakes does not emit errors for shadowing global variables, imports or otherwise, unless it's done such that something which was imported can not possibly be used. Like this:
I'm vaguely remembering there was some implementation reason for this bug, and maybe it was too difficult to fix. But that was years ago...worth at least investigating. |
Original report by lelegaifax on Launchpad:
Consider the following script:
Pyflakes emits:
Both disappears if
bar
is actually used, so the following is clean:The text was updated successfully, but these errors were encountered: