Split out of #408. Confirmed live on main @ da74283 and on the bidirectionaltype-inference branch.
The code
crates/basilisk-checker/src/rules/aliases_implicit.rs:69-83
// Scan the raw import source text for `TypeAlias as <alias>` patterns.
let Some(import_text) = slice_span(&module.source, import.span) else { continue };
for (pos, marker) in import_text.match_indices("TypeAlias as ") {
let after = &import_text[pos + marker.len()..];
let alias: String = after
.chars()
.take_while(|c| c.is_alphanumeric() || *c == '_')
.collect();
if !alias.is_empty() && alias != "TypeAlias" {
names.push(alias);
}
}
Import aliases are recovered by substring-matching raw source text, against the repo rule "avoid regex to parse anything, use ruff". Ruff already gives alias.name and alias.asname as structured fields on the import node.
Failing cases
The literal marker "TypeAlias as " requires exactly one space on each side of as. Any other legal spelling silently fails, and the resulting alias name is never registered — so aliases_implicit skips every variable annotated with it:
from typing import TypeAlias as TA # two spaces
X: TA = [int, str] # not flagged
With two spaces the marker still matches, but after begins with a space, take_while yields the empty string, and the alias is dropped.
from typing import (
TypeAlias as
TA,
)
Y: TA = True # not flagged
Here as is followed by a newline, the marker never matches at all, and TA is unknown.
Because the scanner has no notion of tokens, it also cannot distinguish code from string or comment content inside the span.
Duplication
A second, independent resolution of the same spellings already exists at assignment_compatibility/mod.rs:296-301, which resolves TypeAlias, typing.TypeAlias, t.TypeAlias, and TypeAlias as TA through the name cascade — structurally, and correctly. The rule reimplements it worse.
Fix
Delete the scanner and resolve TypeAlias through the existing name cascade, reading asname from the import node. This removes the duplication flagged by the repo's DRY rule at the same time.
Split out of #408. Confirmed live on
main@da74283and on thebidirectionaltype-inferencebranch.The code
crates/basilisk-checker/src/rules/aliases_implicit.rs:69-83Import aliases are recovered by substring-matching raw source text, against the repo rule "avoid regex to parse anything, use ruff". Ruff already gives
alias.nameandalias.asnameas structured fields on the import node.Failing cases
The literal marker
"TypeAlias as "requires exactly one space on each side ofas. Any other legal spelling silently fails, and the resulting alias name is never registered — soaliases_implicitskips every variable annotated with it:With two spaces the marker still matches, but
afterbegins with a space,take_whileyields the empty string, and the alias is dropped.Here
asis followed by a newline, the marker never matches at all, andTAis unknown.Because the scanner has no notion of tokens, it also cannot distinguish code from string or comment content inside the span.
Duplication
A second, independent resolution of the same spellings already exists at
assignment_compatibility/mod.rs:296-301, which resolvesTypeAlias,typing.TypeAlias,t.TypeAlias, andTypeAlias as TAthrough the name cascade — structurally, and correctly. The rule reimplements it worse.Fix
Delete the scanner and resolve
TypeAliasthrough the existing name cascade, readingasnamefrom the import node. This removes the duplication flagged by the repo's DRY rule at the same time.