ruff
ruff copied to clipboard
An equivalent to `force_sort_within_sections` from isort
I personally prefer to sort imports like this (which used to be the standard sorting for the Python extension on VS Code):
import numpy as np
import torch
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
import tqdm
from .my_module import my_func
as opposed to this sorting, which is how isort (and ruff) sorts by default:
import numpy as np
import torch
import torch.nn.functional as F
import tqdm
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
from .my_module import my_func
(Notice how tqdm is sandwiched there in the torch imports.)
With isort, I can achieve the desired sorting with the force_sort_within_sections option. Would you be interested in supporting this as well?
Yeah we can probably support this (and I don't mind doing so), though it requires a bit of refactoring to the import model.
Added in #1635.