pythonpycharmauto-import

Disable auto import after return in PyCharm


How to disable auto import when I return in my code

enter image description here

enter image description here

As shown in the diagram above,after I choose re.findall at row: 20. PyCharm will auto append "import \ re" for me,I want to close that but I don`t know the method.


Solution

  • For Python auto-import can't be fully disabled in the current version of PyCharm, see Disable auto import. Only the import style and tooltip can be adjusted, see Automatically add import statements.

    The example in the question with a line break is not typical, one possible reason for this is the file extension being .config and not .py.

    import \
        re
    

    What is happening is the line is being wrapped, a combination of several settings can cause this. Go to File > Settings > Editor > Code Style > Python > Wrapping and Braces. If the first option Hard wrap at: is set to a high value (e.g 120) then confirm the option in "From" Import Statements is Do not Warp. See the screenshot:

    enter image description here

    One side-effect is that imports might not wrap automatically on longer lines. However, you can always refactor the code afterwards.