Disabling import sorting dose not work.

I tried to disable "sort import statements", but my imports are still sorted each time I format the file. 

I need to disable import sorting because the first import hooks a function call and need to remain first. 

If there is any why to fix the issue even without disabling sort import statements. I'm also using 

# noinspection PyUnresolvedReferences
import HookOpenFile # Do Not Delete - Used for hooking 'open()'

 to prevent the import from being deleted.

4 comments
Comment actions Permalink

Hi, could you please provide a minimal code sample to reproduce the issue?

1
Comment actions Permalink

I would like that 

import HookOpenFile

Would remain first.

#!/usr/bin/python

# noinspection PyUnresolvedReferences
import HookOpenFile # Do Not Delete - Used for hooking 'open()']

import os

class Test():
def __init__(self):
os.getcwd()

But when running the reformatter(with sort import statements turned off ) I get :

#!/usr/bin/python

import os

# noinspection PyUnresolvedReferences
import HookOpenFile # Do Not Delete - Used for hooking 'open()']


class Test():
def __init__(self):
os.getcwd()
0
Comment actions Permalink

Thank you for the example. 

Yes, when optimizing imports, there's no way to disable this kind of sorting (putting stdlib imports first). Instead, you can run formatter without optimizing imports. To do this, you can either use a shortcut for "Reformat code" action, or you can disable "Optimize imports" in the reformat file dialog.

Does this work for you?

1
Comment actions Permalink

It did solve the issue for me

But it's a shame I won't be able to use the built-in import optimizer because of it.

0

Please sign in to leave a comment.