Repository: astral-sh/ruff
File: crates/ruff_workspace/src/options.rs (Rust)

Code before:
                    .map(|(module, alias)| (module.into_string(), alias.into_string())),
            );
        }

        // Merge preview aliases if preview mode is enabled
        if preview.is_enabled() {
            aliases.extend(flake8_import_conventions::settings::preview_aliases());
        }

        let mut normalized_aliases: FxHashMap<String, String> = FxHashMap::default();
        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 mut banned_aliases = self.banned_aliases.unwrap_or_default();

        // Merge preview banned aliases if preview mode is enabled
        if preview.is_enabled() {
            banned_aliases.extend(flake8_import_conventions::settings::preview_banned_aliases());
        }

        Ok(flake8_import_conventions::settings::Settings {
            aliases: normalized_aliases,
            banned_aliases,
            banned_from: self.banned_from.unwrap_or_default(),
        })
    }
}

/// Options for the `flake8-pytest-style` plugin
#[derive(
    Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, OptionsMetadata, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8PytestStyleOptions {
    /// Boolean flag specifying whether `@pytest.fixture()` without parameters
    /// should have parentheses. If the option is set to `false` (the default),
    /// `@pytest.fixture` is valid and `@pytest.fixture()` is invalid. If set
    /// to `true`, `@pytest.fixture()` is valid and `@pytest.fixture` is
    /// invalid.
    #[option(
        default = "false",
        value_type = "bool",
        example = "fixture-parentheses = true"

Review comment (suggestion):
Same as above, we should only do this in the `or_default` case.

Code after:
        if &*name == "__debug__" {
            return Err(de::Error::invalid_value(
                de::Unexpected::Str(&name),
                &"an assignable Python identifier",
            ));
        }
        if is_identifier(&name) {
            Ok(Self(name))
        } else {
            Err(de::Error::invalid_value(
                de::Unexpected::Str(&name),
                &"a Python identifier",
            ))
        }
    }
}

impl Flake8ImportConventionsOptions {
    pub fn try_into_settings(
        self,
        preview: PreviewMode,
    ) -> anyhow::Result<flake8_import_conventions::settings::Settings> {
        let mut aliases: FxHashMap<String, String> = match self.aliases {
            Some(options_aliases) => options_aliases
                .into_iter()
                .map(|(module, alias)| (module.into_string(), alias.into_string()))
                .collect(),
            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();
        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)
        });