astral-sh/ruff · error

cannot set default value for variadic parameter

Error message

cannot set default value for variadic parameter

What it means

Fires in the parameter-signature builder when with_default_type is called on a variadic (*args-style) parameter. Variadic parameters cannot carry defaults in Python, so the builder rejects the operation; reaching it means the caller constructed an invalid signature.

Source

Thrown at crates/ty_python_semantic/src/types/signatures.rs:5611

        self.annotated_type = inferred_type;
        self.inferred_annotation = true;
        self
    }

    pub(crate) fn with_starred_annotation(mut self) -> Self {
        self.annotation_kind = ParameterAnnotationKind::Starred;
        self
    }

    pub(crate) fn with_default_type(mut self, default: Type<'db>) -> Self {
        match &mut self.kind {
            ParameterKind::PositionalOnly { default_type, .. }
            | ParameterKind::PositionalOrKeyword { default_type, .. }
            | ParameterKind::KeywordOnly { default_type, .. } => {
                *default_type = Some(ParameterDefault::Inferred(default));
            }
            ParameterKind::Variadic { .. } | ParameterKind::KeywordVariadic { .. } => {
                panic!("cannot set default value for variadic parameter")
            }
        }
        self
    }

    pub(crate) fn with_optional_default_type(self, default: Option<Type<'db>>) -> Self {
        if let Some(default) = default {
            self.with_default_type(default)
        } else {
            self
        }
    }

    /// Set the source definition represented by this parameter.
    pub(crate) fn with_definition(mut self, definition: Option<Definition<'db>>) -> Self {
        self.definition = definition;
        self
    }

View on GitHub (pinned to 15f3fe6b15)

Solutions

  1. Only call with_default_type for positional-only, positional-or-keyword, or keyword-only parameters
  2. Model variadic defaults separately or reject them at the call site
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/ty_python_semantic/src/types/signatures.rs:5523 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@15f3fe6b15 (2026-09-05). Data as JSON: /api/errors/576499a27c10978a. Report an issue: GitHub.