False Unused Import Statement in PyCharm?

Mihnea Simian picture Mihnea Simian · Jan 15, 2014 · Viewed 33.7k times · Source

Given this scenario:

b.py:

import A
# A is unused here

c.py:

from b import A
# A is used here

PyCharm complains in b.py that "import A" is an unused import and Optimize imports deletes it, breaking import in c.py

I know these chained imports are not a good practice (although you may use it to implement a facade module), but is it me or is it a PyCharm fail?

Answer

benselme picture benselme · Jan 30, 2014

You can actually use the PyUnresolvedReferences marker to deactivate the inspection for your import statement:

# noinspection PyUnresolvedReferences
import A

Reference: PyCharm bug PY-2240