hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.56k stars 290 forks source link

Imports moved above a sys.path.insert call, breaking code #613

Closed marsfan closed 2 years ago

marsfan commented 2 years ago

Sometimes I need to add a path to the system path to be able to import a file. (Commonly when working with Sphinx).

When I then run autopep8 to format the file, it moves the imports to be above the call to sys.path.insert, breaking the code.


Python Code


import os
import sys

sys.path.insert(0, os.path.abspath(".."))
import test_package

Command Line and Configuration

Command Line

$ autopep8 conf.py

Your Environment

marsfan commented 2 years ago

Ok. I just realized that this is likely due to pycodestyle, not this extension. Closing

siddhpant commented 3 months ago

wdym? This is a regression as autopep8 should be safe.