mirror of
https://github.com/astral-sh/ruff
synced 2026-01-11 08:34:29 -05:00
Stabilize new strategy for classifying imports as first party (#20268)
This stabilizes the behavior introduced in #16565 which (roughly) tries to match an import like `import a.b.c` to an actual directory path `a/b/c` in order to label it as first-party, rather than simply looking for a directory `a`. Mainly this affects the sorting of imports in the presence of namespace packages, but a few other rules are affected as well.
This commit is contained in:
@@ -310,8 +310,7 @@ my_project
|
||||
When Ruff sees an import like `import foo`, it will then iterate over the `src` directories,
|
||||
looking for a corresponding Python module (in reality, a directory named `foo` or a file named
|
||||
`foo.py`). For module paths with multiple components like `import foo.bar`,
|
||||
the default behavior is to search only for a directory named `foo` or a file
|
||||
named `foo.py`. However, if `preview` is enabled, Ruff will require that the full relative path `foo/bar` exists as a directory, or that `foo/bar.py` or `foo/bar.pyi` exist as files. Finally, imports of the form `from foo import bar`, Ruff will only use `foo` when determining whether a module is first-party or third-party.
|
||||
Ruff will require that the full relative path `foo/bar` exists as a directory, or that `foo/bar.py` or `foo/bar.pyi` exist as files. Finally, for imports of the form `from foo import bar`, Ruff will only use `foo` when determining whether a module is first-party or third-party.
|
||||
|
||||
If there is a directory
|
||||
whose name matches a third-party package, but does not contain Python code,
|
||||
|
||||
Reference in New Issue
Block a user