Pythonvalidate_argspec

validate_argspec

Validate an argspec string and inspect the parsed argument slots.

validate_argspecfunction#

validate_argspec(spec: str) -> ValidateArgspecResult

Validate an xparse-style argspec string and report its parsed slots.

Use it to self-check an argspec before injecting a custom command into a Parser. It never raises on a malformed spec; instead the result's valid is False and error carries the reason.

ParameterTypeDescription
specstr

The argspec string, such as "o m", "s m{}", or "d<(,)><[,]>".

Returns
ValidateArgspecResult —

A ValidateArgspecResult dict: valid, error, arg_count, and parsed (the per-slot breakdown when valid).

Python
texform.validate_argspec("o m")  # {'valid': True, 'error': None, 'arg_count': 2, 'parsed': [...]}

ValidateArgspecResultdict type#

The outcome of validating an argspec string with validate_argspec.

On success, valid is True and arg_count / parsed describe the slots; on failure, valid is False and error carries the reason while arg_count and parsed are None.

FieldTypeDescription
validbool

Whether the specification string parsed.

errorstr | None

The error message when invalid, otherwise None.

arg_countint | None

The number of argument slots when valid, otherwise None.

parsedlist[ParsedArgSpecSlot] | None

The per-slot breakdown when valid, otherwise None.

ParsedArgSpecSlotdict type#

One parsed argument slot of an xparse-style specification.

A presentation-oriented view of the internal argspec model, so tooling can consume argspecs without depending on internal crates.

FieldTypeDescription
requiredbool

Whether the argument is mandatory (True) or optional.

no_leading_spacebool

Whether leading whitespace before the argument is disallowed.

nullablebool

Whether an absent optional argument yields a null value.

kinddict[str, Any]

The value kind the slot accepts; a dict with a type field, one of the ArgSpecKindType values. A content kind also carries a mode of "math" or "text".

formdict[str, Any]

The syntactic form the slot takes; a dict with a type field, one of the ArgSpecFormType values. A paired form carries a pairs list of open/close delimiter descriptors.

ArgSpecKindTypetype#

Literal['content', 'operatorname', 'delimiter', 'csname', 'dimension', 'integer', 'keyval', 'column', 'star']

Value kind of one parsed argspec slot (content, delimiter, star, ...).

ArgSpecFormTypetype#

Literal['standard', 'star', 'group', 'until', 'delimited', 'paired']

Surface form of one parsed argspec slot (mandatory, optional group, paired, ...).