micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

all: Enable ruff E401,E402 import lints.

Open projectgus opened this issue 1 year ago • 6 comments
trafficstars

Mostly small cleanups, and explicit disable for examples/tests which insert the current directory into the path before importing.

projectgus avatar May 14 '24 05:05 projectgus

This is a bit of a change, making each import go on a separate line. But I guess we have to do that because we have committed to using ruff check for our style.

Luckily there is no difference in bytecode between import a, b and import a; import b.

dpgeorge avatar May 15 '24 04:05 dpgeorge

This is a bit of a change, making each import go on a separate line. But I guess we have to do that because we have committed to using ruff check for our style.

I think we could reasonably commit to ignoring these, especially E402 (imports not at top ) because we need to add noqa for legitimate use case in quite a few places.

However, the current usage is pretty arbitrary - sometimes imports on the same line, sometimes imports on different lines, sometimes the same source file has both approaches for no apparent reason. So it is also nice to be consistent, IMO.

projectgus avatar May 15 '24 07:05 projectgus

Each import on its own line (or even going further: isort style sorted and grouped by type) just seems cleaner overall: more readable, nicer diffs, consistency.

stinos avatar May 15 '24 07:05 stinos

All imports on one line (or even going further: isort style sorted and grouped) just seems cleaner overall: more readable, nicer diffs, consistency.

I don't exactly disagree, but I do want to point out that these individual small differences in style preference is why many projects just pick a formatter (like ruff) and have it auto-format the code. Instant consistency, minimal time overhead. No one gets their preferred individual style, but the code base all has the same style.

projectgus avatar May 15 '24 08:05 projectgus

or even going further: isort style sorted and grouped

AFAIK, isort keeps separate modules on separate import lines??

nicer diffs

Aren't diffs smaller if imports are on separate lines?

dpgeorge avatar May 15 '24 08:05 dpgeorge

AFAIK, isort keeps separate modules on separate import lines??

Depends, it has a bit too much configuration options actually. Though I think ruff's isort implementation is betrer in that regard.

Aren't diffs smaller if imports are on separate lines?

Oops. I actually did mean to say 'all imports on their own line' ! Will edit original comment.

stinos avatar May 15 '24 08:05 stinos

OK, we're all on the same page now :)

Merged.

dpgeorge avatar May 17 '24 07:05 dpgeorge