News for hackers. Stuff that matters.
Re:Boring Python: Code Quality by anderskaseorg on Tuesday December 20, 2022 @03:04AM (#34062974)
If you aren’t happy with Flake8, Pylint, and isort (or maybe if you are!), I recommend checking out Ruff:

https://github.com/charliermarsh/ruff

It’s literally 100 times faster, with comparable coverage to Flake8 plus dozens of plugins, automatic fixes, and very active development.

Re:Boring Python: Code Quality by gjulianm on Tuesday December 20, 2022 @04:08AM (#34063467)
Does ruff replace isort? Because I'm really unhappy with it, it doesn't work with tabs and conflicts with yapf all the time.
Re:Boring Python: Code Quality by anderskaseorg on Tuesday December 20, 2022 @04:38AM (#34063694)
Yes, as of last month. I’m not sure if it works with YAPF; it’s designed to work with Black and doesn’t currently have many of isort’s configuration options. Worth a try!
Re:Boring Python: Code Quality by gjulianm on Tuesday December 20, 2022 @07:14AM (#34064839)
Thanks! The configuration options don't matter too much, I was really unhappy with the options isort gives.
Re:Boring Python: Code Quality by drcongo on Tuesday December 20, 2022 @05:00AM (#34063841)
> it doesn't work with tabs

What do you mean by this? Are you indenting Python with tabs?

Re:Boring Python: Code Quality by makapuf on Tuesday December 20, 2022 @05:26AM (#34063997)
If your import statements are indented, they must be in control statements (try/except or conditional imports, I fail to see why you would put those in a loop) thus they will be difficult to reorder if you import another module (with different name or stdlib status) on import error.
Re:Boring Python: Code Quality by drcongo on Tuesday December 20, 2022 @05:44AM (#34064126)
I'm not sure what you mean here, but package names can be indented without conditionals or tries, as in...

  from application.module.modules import (
      Model1, Model2, Model3, Model4, Model5, Model6
  )
iSort handles this fine if you're using spaces for indentation.
Re:Boring Python: Code Quality by eCa on Tuesday December 20, 2022 @05:52AM (#34064197)
> I have no idea how to <pre> on HN

  Two or more leading spaces on each line.[1]
[1] https://news.ycombinator.com/formatdoc
Re:Boring Python: Code Quality by drcongo on Tuesday December 20, 2022 @06:04AM (#34064275)
Thank you, fixed it up.
Re:Boring Python: Code Quality by gjulianm on Tuesday December 20, 2022 @07:19AM (#34064884)
Yes. The code started as being indented by tabs, so changing it now is a mess. Also, not to start a flamewar, but I've always preferred tabs to spaces in any language, I find them more reliable, easier to use...
Re:Boring Python: Code Quality by drcongo on Tuesday December 20, 2022 @08:04AM (#34065282)
Not going to argue about your personal preference, but in Python spaces for indentation isn't just a personal preference - you'll run into a fair amount of issues with that, this one being just the tip of the iceberg.
Re:Boring Python: Code Quality by gjulianm on Tuesday December 20, 2022 @08:34AM (#34065618)
Apart from isort not knowing how to deal with tabs, and changing the defaults "spaces" to "tabs" in the tools (along with line length too, because for some reason the 80 character limit is set in stone even though it's absolutely outdated) I haven't had many issues. And this has been running for years already.
Re:Boring Python: Code Quality by dontlaugh on Tuesday December 20, 2022 @09:10AM (#34066099)
Not necessarily. Consistently indenting with tabs and aligning with spaces does work, but is tricky to enforce.
Re:Boring Python: Code Quality by Stratoscope on Tuesday December 20, 2022 @12:05PM (#34068766)
The key to success with tabs in any language is simple: Don't use alignment.

Instead, only use indentation.

It is interesting to note that Black-formatted code uses indentation only and never uses alignment. It would be perfectly compatible with tabs, unlike Google-formatted code which relies heavily on column alignment.

Re:Boring Python: Code Quality by captnswing on Tuesday December 20, 2022 @08:00AM (#34065242)
yes it does. see see https://github.com/charliermarsh/ruff#supported-rules for the rules it supports. "IOO1" being the code for isort

relevant section from my pyproject.toml

  [tool.ruff]
  line-length = 88
  # pyflakes, pycodestyle, isort
  select = ["F", "E", "W", "I001"]
Re:Boring Python: Code Quality by stinos on Wednesday December 21, 2022 @03:38PM (#34086082)
But does it just lint, or also effectively sort the imports?
Re:Boring Python: Code Quality by stinos on Thursday December 22, 2022 @03:10AM (#34091000)
Re:Boring Python: Code Quality by drcongo on Tuesday December 20, 2022 @05:41AM (#34064105)
Just installed this along with ruff-lsp and I'm in love already, thank you!
Re:Boring Python: Code Quality by captnswing on Tuesday December 20, 2022 @07:58AM (#34065224)
+100 on ruff.

replaced both flake8 and isort across all my projects

Re:Boring Python: Code Quality by trymas on Tuesday December 20, 2022 @11:16AM (#34067965)
TIL and seems very nice project.

Though their `v0.0.X` versioning is very funny to me (https://0ver.org/).

Re:Boring Python: Code Quality by timothycrosley on Tuesday December 20, 2022 @02:06PM (#34070724)
FWIW, I wrote isort, but am seriously considering migrating my projects to use Ruff. Long term I think the design is just better over the variety of tools we use within the Python ecosystem today. The fact we have a plethora of projects that are meant to run per a commit with each one reparsing the AST independently, and often using a different approach to do so, just feels untenable long term to me.
Re:Boring Python: Code Quality by BeefySwain on Tuesday December 20, 2022 @05:47PM (#34073904)
That is about as large of an endorsement as I can conceive. Will definitely have to check it out!
Re:Boring Python: Code Quality by muxator on Wednesday December 21, 2022 @06:46AM (#34079406)
BTW, thank you for isort!