Search code examples
pythonpycharm

PyCharm removes unused imports when moving a file


I'm using Pycharm for moving files inside my project and PyCharm updates the imports in the project to the new path which is great.

The problem is that it also removes unused imports from those files. This is a very bad behavior for me and I can't find a way to stop this.

I can't check whether it did that every time because sometimes its hundreds of files.


Solution

  • It is currently not possible. This is a known issue: PY-54707. Also discussed in this thread: here.

    You can use this to protect the a spesific import from removal:

    # noinspection PyUnresolvedReferences