PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.53k stars 583 forks source link

isort messes with comments after the end of the import section #2162

Open AlexKirko opened 1 year ago

AlexKirko commented 1 year ago

We have a file that starts like this:

from math import log, sqrt

import numpy as np
from scipy.signal import argrelmax

# TOCONSIDER: See also smth smth

def my_function():
    . . .

When isort is run on this, it deletes the line before # TOCONSIDER, causing a PEP8 violation.

I'm well aware that removing the line between the comment and the function or removing one before and adding one after fixes it, but maybe isort shouldn't do anything after the last valid import in case they don't belong to it? That looks more like flake8 territory.

Expected behavior

This chunk of code should remain intact:

from math import log, sqrt

import numpy as np
from scipy.signal import argrelmax

# TOCONSIDER: See also smth smth

def my_function():
    . . .