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?

3 comments

Please try pressing Alt-Enter on the unused import, pressing the right arrow key to show the inspection options, and selecting "Suppress for statement".

4

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...

// noinspection ES6UnusedImports
import unsplash_001 from '../assets/unsplash-001.jpeg'
// noinspection ES6UnusedImports
import unsplash_002 from '../assets/unsplash-002.jpeg'

// noinspection ES6UnusedImports
import lorempixel_003 from '../assets/lorempixel-003.jpeg'
// noinspection ES6UnusedImports
import lorempixel_004 from '../assets/lorempixel-004.jpeg'
// noinspection ES6UnusedImports
import lorempixel_005 from '../assets/lorempixel-005.jpeg'
// noinspection ES6UnusedImports
import lorempixel_006 from '../assets/lorempixel-006.jpeg'


Something like

// noinspection ES6UnusedImports start
import unsplash_001 from '../assets/unsplash-001.jpeg'
import unsplash_002 from '../assets/unsplash-002.jpeg'

import lorempixel_003 from '../assets/lorempixel-003.jpeg'
import lorempixel_004 from '../assets/lorempixel-004.jpeg'
import lorempixel_005 from '../assets/lorempixel-005.jpeg'
import lorempixel_006 from '../assets/lorempixel-006.jpeg'
// noinspection ES6UnusedImports end

I can dream :)
0

Please sign in to leave a comment.