astral-sh/ruff · error · ValueError

`*` must be at the end: {rule}

Error message

`*` must be at the end: {rule}

What it means

'T*' is the AST DSL shorthand for Vec<T>. split_sequence_type() accepts the star only as a trailing marker appearing exactly once; any other placement ('*Name', 'Name**', 'Vec<*T>') raises this ValueError with the offending rule.

Source

Thrown at crates/ruff_python_ast/generate.py:246

    inner_type = rust_type_str[open_bracket_index + 1 : close_bracket_index].strip()
    inner_type = inner_type.replace("crate::", "")
    return inner_type


class SequenceKind(Enum):
    VEC = "vec"
    BOXED_SLICE = "boxed_slice"
    THIN_VEC = "thin_vec"


def split_sequence_type(rule: str) -> tuple[SequenceKind | None, str]:
    if "&" in rule:
        raise ValueError(f"`&T*` is unsupported; use `Box<[T]>`: {rule}")

    if "*" in rule:
        if rule.endswith("*") and rule.count("*") == 1:
            return SequenceKind.VEC, rule[:-1]
        raise ValueError(f"`*` must be at the end: {rule}")

    for prefix, suffix, sequence_kind in (
        ("Vec<", ">", SequenceKind.VEC),
        ("ThinVec<", ">", SequenceKind.THIN_VEC),
        ("Box<[", "]>", SequenceKind.BOXED_SLICE),
    ):
        if rule.startswith(prefix):
            if not rule.endswith(suffix):
                raise ValueError(f"Unclosed collection type: {rule}")
            return sequence_kind, rule[len(prefix) : -len(suffix)]

    return None, rule


@dataclass
class FieldType:
    rule: str
    name: str

View on GitHub (pinned to d1087a4b9e)

Solutions

  1. Move the single '*' to the very end of the rule: 'Name*'.
  2. Remove any extra '*' characters.
  3. Re-run the generator to confirm the rule parses.

Example fix

# before
names: *Name

# after
names: Name*
Defensive patterns

Strategy: validation

Validate before calling

def rule_ok(rule: str) -> bool:
    return '*' not in rule or (rule.endswith('*') and rule.count('*') == 1)

Prevention

When it happens

Trigger: Adding or editing a field rule where the '*' is not the final character or appears more than once, then running generate.py.

Common situations: Typos when writing sequence shorthand; pasting Rust pointer syntax (e.g. '*const T') into the DSL.

Related errors


AI-assisted analysis of astral-sh/ruff@d1087a4b9e (2026-08-20). Data as JSON: /api/errors/d9b163ab2dd29542. Report an issue: GitHub.