Marking an import to prevent deleting it with "optimize imports"
In django I often use something like
in models.py or urls.py:
import signals
I don't use singlas later in code, this is just to run signals.py code with django. PyCharm marks this import as unused, and will delete it on every usage of "optimize import".
Is it possible to prevent PyCharm doing that? Any magic comment/annotation?
Please sign in to leave a comment.
Please try pressing Alt-Enter on the unused import, pressing the right arrow key to show the inspection options, and selecting "Suppress for statement".
Add a comment before the import...
PyCharm 2019.3.3 does not offer a "Suppress for statement" option in the drop down, however it does hint at the solution as the inspection violation is "Unresolved References". For a complete list of inspection suppression comments, see https://www.jetbrains.com/help/pycharm/disabling-and-enabling-inspections.html
Hi,
Following on from this... is there a way to mark a block of code like this, rather than do one line at a time?
So instead of this...
It's actually very annoying they don't offer it as a hint anymore, and the name is completely misleading. So if you really need it (like models definition or whatever) it's bad user experience.
Thank you.
me too !!