{"record":{"id":"8bdbd62aab834ba5","repo":"astral-sh/ruff","slug":"invalid-alias-for-module-module-alias-normali","errorCode":null,"errorMessage":"Invalid alias for module '{module}': alias normalizes to '__debug__', which is not allowed.","messagePattern":"Invalid alias for module '(.+?)': alias normalizes to '__debug__', which is not allowed\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_workspace/src/options.rs","lineNumber":1811,"sourceCode":"            None => flake8_import_conventions::settings::default_aliases(preview),\n        };\n        if let Some(extend_aliases) = self.extend_aliases {\n            aliases.extend(\n                extend_aliases\n                    .into_iter()\n                    .map(|(module, alias)| (module.into_string(), alias.into_string())),\n            );\n        }\n\n        let mut normalized_aliases: FxHashMap<String, String> = FxHashMap::default();\n        #[expect(\n            clippy::iter_over_hash_type,\n            reason = \"every invalid alias is rejected, regardless of which one is reported first\"\n        )]\n        for (module, alias) in aliases {\n            let normalized_alias = alias.nfkc().collect::<String>();\n            if normalized_alias == \"__debug__\" {\n                anyhow::bail!(\n                    \"Invalid alias for module '{module}': alias normalizes to '__debug__', \\\n                    which is not allowed.\"\n                );\n            }\n            normalized_aliases.insert(module, normalized_alias);\n        }\n\n        let banned_aliases = self.banned_aliases.unwrap_or_else(|| {\n            flake8_import_conventions::settings::default_banned_aliases(preview)\n        });\n\n        Ok(flake8_import_conventions::settings::Settings {\n            aliases: normalized_aliases,\n            banned_aliases,\n            banned_from: self.banned_from.unwrap_or_default(),\n        })\n    }\n}","sourceCodeStart":1793,"sourceCodeEnd":1829,"githubUrl":"https://github.com/astral-sh/ruff/blob/5bb508f59481c1a02d5c7ff8568b9ffd8a763eef/crates/ruff_workspace/src/options.rs#L1793-L1829","documentation":"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.","triggerScenarios":"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).","commonSituations":"Typo in a module-mapping entry; copy-pasted config containing `__debug__`; internationalized identifiers whose NFKC normalization yields `__debug__`.","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"],"exampleFix":"# before (ruff.toml)\n[src]\nmodule-mapping = { mymod = \"__debug__\" }\n\n# after\n[src]\nmodule-mapping = { mymod = \"debug_helpers\" }","handlingStrategy":"validation","validationCode":"import unicodedata\nimport sys\n\ndef check_alias(module: str, alias: str) -> None:\n    if unicodedata.normalize(\"NFKC\", alias) == \"__debug__\":\n        sys.exit(f\"Invalid alias for module '{module}': normalizes to '__debug__'\")\n\n# run over [src] module-mapping entries before invoking ruff","typeGuard":null,"tryCatchPattern":"import subprocess\np = subprocess.run([\"ruff\", \"check\", \".\"], capture_output=True, text=True)\nif p.returncode != 0 and \"__debug__\" in p.stderr:\n    fix_module_mapping(); retry()","preventionTips":["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"],"tags":["configuration","python","unicode"],"backgroundTag":"invalid-config-value","analyzedSha":"5bb508f59481c1a02d5c7ff8568b9ffd8a763eef","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}