Support `flake8-lazy` style relative import in `__lazy_modules__`
Summary
The names inside __lazy_modules__ always have to be absolute, so in order to make a relative import lazy, you need to put the corresponding absolute import into __lazy_modules__ which breaks symmetry.
While ruff is generally aware of a project's structure when linting it, so relative imports can easily be mapped to absolute ones, this is not as much the case with flake8 or any of its plugins. While it's certainly possible to add similar project detection and configuration options into a flake8 plugin, it's far from economical to do this and generally a bad idea for a plugin. flake8 would need to add those capabilities itself, which seems unlikely to ever happen.
As a result flake8-lazy chose to support a specific style of f-string generated lazy imports. flake8-type-checking plans to support this style as well:
__lazy_modules__ = [
# matches .lazy
f"{__spec__.parent}.lazy",
# matches ..lazy, but type checkers will complain, since `parent` is `str | None`, so `rsplit` might raise.
f"{__spec__.parent.rsplit('.', 1)[0]}.lazy",
# matches ...lazy and is type safe
f"{(__spec__.parent or '').rsplit('.', 2)[0]}.lazy"
]So we can continue to use ruff and certain flake8 plugins side-by-side I think it's a good idea for ruff to support this style at least at the detection level. I have no strong opinion about whether ruff should ever suggest generating a relative lazy import like that. I can certainly see arguments for it, like also making it easier to tell for humans which lines in __lazy_modules__ map to relative imports, but also arguments against it, such as aesthetics.
Source: astral-sh/ruff