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

Cascading try/except imports report duplicates #116

Closed
pyflakes-bot opened this issue Jan 13, 2012 · 5 comments
Closed

Cascading try/except imports report duplicates #116

pyflakes-bot opened this issue Jan 13, 2012 · 5 comments

Comments

@pyflakes-bot
Copy link

Original report by 4-launchpad-tim-thechases-com on Launchpad:


With the attached example file, pyflakes reports

pf.py:6: redefinition of unused 'connect' from line 3
pf.py:6: redefinition of unused 'PARSE_DECLTYPES' from line 3
pf.py:6: redefinition of unused 'PARSE_COLNAMES' from line 3

They're not redefinitions, but fallbacks in case defining them the first time fails. I don't know if there's a way to catch this, but it's worth noting.

@pyflakes-bot
Copy link
Author

Original comment by 4-launchpad-tim-thechases-com on Launchpad:


@pyflakes-bot
Copy link
Author

Original comment by adiroiban (@adiroiban?) on Launchpad:


This is on the TODO list: pyflakes.test.test_imports.Test.test_tryingMultipleImports

@pyflakes-bot
Copy link
Author

Original comment by fpinard on Launchpad:


The same duplication warning occurs if one assigns the import name, like in:

try:
import signal
except ImportError:
signal = None

This code comes from a program which sometimes runs under Jython, so it could quickly test if "signal" was available.

François

@pyflakes-bot
Copy link
Author

Original comment by saperski on Launchpad:


I think I have a fix for this problem for a slightly different fork of pyflakes here: kevinw/pyflakes#28

@pyflakes-bot
Copy link
Author

Original comment by zbyszek-in on Launchpad:


Tested this on multi-import from http://lxml.de/tutorial.html and it seems to work well.

OTOH, stuff like:
choice = sys.getenv('CHOICE')
if choice == 'A':
import A as backend

if choice == 'B':
import B as backend

don't work, as expected.

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