Pycharm inserting `import` statements inside of function bodies

Answered

I'm not sure when this changed but the newer versions of PyCharm have started inserting `import` statements directly in local scope instead of the top of the module. The first two steps in the process show the expected popups and complete correctly.

 

After completing the Import from… popup, inserts the import statement directly above the usage. In the past, the import was inserted into the import block at the top of the module.

Is this new behavior? and how do I configure PyCharm to only insert import statements in the import block?

0
1 comment

Are you using the latest 2025.2.4? This can occur in case you select import ‘uuid’ locally on the context actions if the caret is on the uuid.

but by default the selection is done for the import  at the top of the module, so it should be working as expected

0

Please sign in to leave a comment.