Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

False Unused Import Statement in PyCharm?

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?

like image 259
Mihnea Simian Avatar asked Jan 15 '14 13:01

Mihnea Simian


People also ask

What does unused import statement mean in Python?

unused import means you imported something that you never used...

What is unused import statement?

Code Inspection: Unused importReports a redundant import statement. This is usually the case if the imported symbols are not used in the source file. To avoid side-effects, consider using bare import import 'packageName' instead of the regular one.


1 Answers

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

# noinspection PyUnresolvedReferences import A 

Reference: PyCharm bug PY-2240

like image 139
benselme Avatar answered Oct 05 '22 16:10

benselme