Unused import warning when importing from try-except block
Brought to you by:
fabioz
PyDev warns me about an unused import when I import modules from a try-except block. For example:
try:
import json #marks unused import
except ImportError:
import simplejson as json #marks unused import
a = json.loads('"hello world"')
I also see this when a type is conditionally imported in an if-else block. For example:
import sys
if sys.platform == 'win32':
from platform import Windows as Platform
else:
from platform import Linux as Platform
print Platform().home_dir
Both imports in the if-else block have warnings. The first warning says "Unused import: Platform", the second says "Import redefinition: Platform".