Search code examples
pythonpython-3.xpycharm

Make IDE/linter ignore a seemingly unused import


At my current work we have an enviroment py file contains the following imports:

from core.entities import * 
from core.entities.hdr import * 
from core.entities.scanner import *

However, all of these imports are seen as "unused" by the ide (Pycharm) and we sometimes experience someone making a commit where these have been removed by the IDE in the process. Is there a way to mark unused imports as not being unused?


Solution

  • Try checking in the "Reformat File" dialog (Ctrl+Alt+Shift+L), uncheck "Optimize imports", if already checked.

    Alternatively, you can add `PyUnresolvedReferences':

    # noinspection PyUnresolvedReferences
    import A
    
    # noinspection PyUnresolvedReferences
    import B
    

    Although there are some reported issues with the reference, https://youtrack.jetbrains.com/issue/PY-19837 .