-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
parserRelated to the parserRelated to the parser
Description
Currently, the path of imports is not formatted, e.g.
import a . bremains as-is. This is due to a bug in our AST:
ruff/crates/ruff_python_ast/src/imports.rs
Lines 6 to 31 in 6824b67
| /// A representation of an individual name imported via any import statement. | |
| #[derive(Debug, Clone, PartialEq, Eq)] | |
| pub enum AnyImport<'a> { | |
| Import(Import<'a>), | |
| ImportFrom(ImportFrom<'a>), | |
| } | |
| /// A representation of an individual name imported via an `import` statement. | |
| #[derive(Debug, Clone, PartialEq, Eq)] | |
| pub struct Import<'a> { | |
| pub name: Alias<'a>, | |
| } | |
| /// A representation of an individual name imported via a `from ... import` statement. | |
| #[derive(Debug, Clone, PartialEq, Eq)] | |
| pub struct ImportFrom<'a> { | |
| pub module: Option<&'a str>, | |
| pub name: Alias<'a>, | |
| pub level: Option<u32>, | |
| } | |
| #[derive(Debug, Clone, PartialEq, Eq)] | |
| pub struct Alias<'a> { | |
| pub name: &'a str, | |
| pub as_name: Option<&'a str>, | |
| } |
The entire path is represented as a single string, even though it should be dot-separated identifier (the parser calls it DottedName, but then emits an identifier), especially since identifier can not contain dots.
- Fix the AST so the import path is a
Vec<Identifier>or something similar - Format import paths by removing whitespace (we can't insert parentheses like we do for dotted expressions)
- Check that
Identifieris only used for strings matching the rules
Metadata
Metadata
Assignees
Labels
parserRelated to the parserRelated to the parser