astral-sh/ruff · error
Invalid alias for module
Error message
Invalid alias for module '{module}': alias normalizes to '__debug__', which is not allowed. What it means
Ruff's configuration supports module aliases via `src.module-mapping` style options. An alias that normalizes (NFKC Unicode normalization) to the reserved name `__debug__` is rejected because `__debug__` is a Python keyword-like builtin module name and aliasing it would produce invalid semantics. Every invalid alias is rejected deterministically.
Solutions
- Edit your configuration and change the alias for the offending module to a valid identifier other than `__debug__`
- Check for visually similar Unicode characters and use plain ASCII `__debug__`-free names
- Re-run Ruff to confirm the configuration loads
Example fix
# before (ruff.toml)
[src]
module-mapping = { mymod = "__debug__" }
# after
[src]
module-mapping = { mymod = "debug_helpers" } Defensive patterns
Strategy: validation
Validate before calling
import unicodedata
import sys
def check_alias(module: str, alias: str) -> None:
if unicodedata.normalize("NFKC", alias) == "__debug__":
sys.exit(f"Invalid alias for module '{module}': normalizes to '__debug__'")
# run over [src] module-mapping entries before invoking ruff Try / catch
import subprocess
p = subprocess.run(["ruff", "check", "."], capture_output=True, text=True)
if p.returncode != 0 and "__debug__" in p.stderr:
fix_module_mapping(); retry() Prevention
- Never use `__debug__` as a module alias in src module-mapping configuration
- Use plain ASCII identifiers for aliases to avoid NFKC normalization surprises
- Validate ruff.toml/pyproject.toml changes by running `ruff check` before committing
When it happens
Trigger: Running `ruff check` or loading configuration where an alias option maps a module to the string `__debug__` (or a string that NFKC-normalizes to it, e.g. containing fullwidth characters).
Common situations: Typo in a module-mapping entry; copy-pasted config containing `__debug__`; internationalized identifiers whose NFKC normalization yields `__debug__`.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Boolean conversion is not supported for union
- Brackets are not balanced for type
- Circular configuration detected
- could not find any ` ` directives in any of the files in
- Could not find the ruff binary in any of the following…
AI-assisted analysis of astral-sh/ruff@5bb508f594 (2026-09-05).
Data as JSON: /api/errors/8bdbd62aab834ba5.
Report an issue: GitHub.
Appendix: source
Thrown at crates/ruff_workspace/src/options.rs:1811
None => flake8_import_conventions::settings::default_aliases(preview),
};
if let Some(extend_aliases) = self.extend_aliases {
aliases.extend(
extend_aliases
.into_iter()
.map(|(module, alias)| (module.into_string(), alias.into_string())),
);
}
let mut normalized_aliases: FxHashMap<String, String> = FxHashMap::default();
#[expect(
clippy::iter_over_hash_type,
reason = "every invalid alias is rejected, regardless of which one is reported first"
)]
for (module, alias) in aliases {
let normalized_alias = alias.nfkc().collect::<String>();
if normalized_alias == "__debug__" {
anyhow::bail!(
"Invalid alias for module '{module}': alias normalizes to '__debug__', \
which is not allowed."
);
}
normalized_aliases.insert(module, normalized_alias);
}
let banned_aliases = self.banned_aliases.unwrap_or_else(|| {
flake8_import_conventions::settings::default_banned_aliases(preview)
});
Ok(flake8_import_conventions::settings::Settings {
aliases: normalized_aliases,
banned_aliases,
banned_from: self.banned_from.unwrap_or_default(),
})
}
}View on GitHub (pinned to 5bb508f594)