Conversation
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
| from build import ProjectBuilder, _ctx | ||
| from build._exceptions import BuildBackendException, BuildException, FailedProcessError | ||
| from build.env import DefaultIsolatedEnv |
There was a problem hiding this comment.
Why were these imports made absolute?
There was a problem hiding this comment.
Because one of them already was, and __main__.py modues have __spec__s that can be None so mypy complains.
There was a problem hiding this comment.
I mention this under "tips" at https://iscinumpy.dev/post/flake8-lazy/.
| from ._exceptions import BuildBackendException, BuildException, FailedProcessError | ||
| from ._types import ConfigSettings, Distribution, StrPath, SubprocessRunner | ||
| from .env import DefaultIsolatedEnv | ||
| from ._types import ConfigSettings, Distribution, StrPath, SubprocessRunner |
There was a problem hiding this comment.
The actual types get imported in __init__ AFAICT so there's nothing to be gained from lazifying these.
There was a problem hiding this comment.
The rules for the imports are in flake-lazy. Basically anything that is unused at top level is lazy.
There was a problem hiding this comment.
I meant tucking it under an if type checking block, sorry for being unclear.
There was a problem hiding this comment.
I added the TC code, that’s supposed to catch everything that can be moved to type checking blocks.
There was a problem hiding this comment.
Okay, so this is for any type checking only imports we might add in the future to go under? Currently, we don’t have any that’d benefit from this.
|
Visually, this is just awful. Can maintenance be automated? Is ruff able to detect extraneous entries? What if we just flipped on lazy imports globally in |
|
Yes, I wrote a tool for maintenance, it’s flake8-lazy. Being intelligent with this is tricky, and there are a few edge cases, such as the There is a way to make all imports lazy by adding three lines, but it ideally needs to be in every file. |
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Description
This adds lazy imports.
I used
uvx flake8-lazy —-apply src/**/*.pyto get the lazy lists.Changelog
docs/changelog/<pr_number>.<type>.rstfeature,bugfix,doc,removal,misc123.feature.rstcontainingAdd custom backend support - by :user:`yourname`Checklist
tox)tox -e fix)tox -e type)tox -e docs)