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

using try keyword in first line and later extra imports autopep8 generates wrong code #630

Open cepelinas9000 opened 2 years ago

cepelinas9000 commented 2 years ago

I ran into this issue when using "try" block in first line, later in code some imports and between them method calls

Python Code

lets call it code_sample1.py

try:  # try
    import pyximport
    pyximport.install(reload_support=True)
except:
    pass
import random
random.seed(12)
from matplotlib import pyplot as plt
print("42")

Command Line

$ autopep8  code_sample1.py
try:  # try
import random                                        
from matplotlib import pyplot as plt        
import pyximport                                    
pyximport.install(reload_support=True) 
except:
    pass
random.seed(12)
print("42")

Your Environment