Nimblesite / Nimblesite/Basilisk
aliases_implicit: `TypeAlias as X` imports resolved by substring scan of raw source, duplicating the real name cascade
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 54
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/basilisk-checker/src/rules/aliases_implicit.rs:69-83 and inspect how the import node exposes name and asname. Compare that logic with assignment_compatibility/mod.rs:296-301 and trace the existing name cascade. Done means aliases are resolved structurally for the shown spacing and multiline cases without the raw-source scanner or duplicated resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100