microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.25k stars 1.15k forks source link

Use VS Code's organize import solution #9288

Closed isidorn closed 1 year ago

isidorn commented 4 years ago

Have the following imports

from __future__ import print_function, division
import math
import numpy as np
import copy
from mlfromscratch.deep_learning.activation_functions import Sigmoid, ReLU, SoftPlus, LeakyReLU
from mlfromscratch.deep_learning.activation_functions import TanH, ELU, SELU, Softmax

Do a context menu > Sort Imports

This is the result. I would expect them just to be sorted, not formated 🐛

from __future__ import division, print_function

import copy
import math

import numpy as np
from mlfromscratch.deep_learning.activation_functions import (ELU, SELU,
                                                              LeakyReLU, ReLU,
                                                              Sigmoid, Softmax,
                                                              SoftPlus, TanH)
mikeroll commented 4 years ago

I'd argue this is not a bug, since this is how isort works - it will wrap overly long lines in addition to sorting them. You may choose between different wrap flavours, or disable wrapping on a per-line basis with # NOQA. It's all right there in isort's readme - https://github.com/timothycrosley/isort#multi-line-output-modes

isidorn commented 4 years ago

Then I argue that Sort Imports is not a good label for this action. Shuold this action be called Format Imports. Since that seems to be what the action is doing at the end.

mikeroll commented 4 years ago

Organize Imports could also be a an option (looking at vscode's generic source.organizeImports action).

isidorn commented 4 years ago

Yes, organize imports makes perfect sense.

brettcannon commented 4 years ago

Thank you for the suggestion! We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

luabud commented 4 years ago

We should use source.organizeImports to "Organize Imports" instead

karthiknadig commented 1 year ago

This is done via the isort extension.