larksuite/cli · error · ValueError

unsupported complemented XSD character class \{escaped} insi

Error message

unsupported complemented XSD character class \{escaped} inside []

What it means

python_pattern_for_xsd translates XSD regex character shortcuts to Python regex. Inside a bracketed character class, \S (complemented whitespace class) cannot be expressed in the validator's translation, so it raises this ValueError. Outside a class, \S becomes [^ \t\n\r], but inside [] the negated form would change class semantics unsafely, so the validator refuses rather than produce a wrong pattern.

Source

Thrown at skills/lark-slides/scripts/sxsd_validator.py:549

        return scalar_value_for_type(rule.base, value, model, resolving)
    finally:
        resolving.remove(type_name)


@lru_cache(maxsize=32)
def python_pattern_for_xsd(pattern: str) -> str:
    translated: list[str] = []
    in_character_class = False
    index = 0
    while index < len(pattern):
        char = pattern[index]
        if char == "\\" and index + 1 < len(pattern):
            escaped = pattern[index + 1]
            if escaped in {"s", "S"}:
                body = r" \t\n\r"
                if in_character_class:
                    if escaped == "S":
                        raise ValueError(
                            f"unsupported complemented XSD character class \\{escaped} inside []"
                        )
                    translated.append(body)
                else:
                    prefix = "^" if escaped == "S" else ""
                    translated.append(f"[{prefix}{body}]")
                index += 2
                continue
            translated.extend((char, escaped))
            index += 2
            continue
        if char == "[":
            in_character_class = True
        elif char == "]":
            in_character_class = False
        elif char == "." and not in_character_class:
            translated.append(r"[^\n\r]")
            index += 1

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Rewrite the pattern to avoid \S inside [], e.g. use a negated outer class like [^ \t\n\r] instead of [\S].
  2. Restructure the pattern so \S appears outside the character class (e.g. '[a-z]\\S' if that matches intent).
  3. Enumerate the allowed characters explicitly in the class.
  4. If you control the schema, prefer patterns using only classes/escapes the validator supports.

Example fix

// before
<xsd:pattern value="[\S]{4}"/>
// after
<xsd:pattern value="[^ \t\n\r]{4}"/>
Defensive patterns

Strategy: try-catch

Validate before calling

import re

def uses_complemented_class_shortcut(xsd_pattern):
    # crude pre-check: \S appearing inside an unclosed [ ... ] span
    depth = 0
    i = 0
    while i < len(xsd_pattern):
        if xsd_pattern[i] == '\\' and i + 1 < len(xsd_pattern):
            if depth > 0 and xsd_pattern[i + 1] == 'S':
                return True
            i += 2
            continue
        if xsd_pattern[i] == '[':
            depth += 1
        elif xsd_pattern[i] == ']':
            depth = max(0, depth - 1)
        i += 1
    return False

Type guard

def safe_xsd_pattern(p):
    from functools import lru_cache
    try:
        python_pattern_for_xsd(p)
        return p
    except ValueError:
        return None

Try / catch

try:
    matches = xsd_pattern_matches(pattern, value)
except ValueError as e:
    print(f'rewrite schema pattern without \\S inside []: {e}')

Prevention

When it happens

Trigger: Validating an XSD pattern facet (via xsd_pattern_matches) whose pattern contains \S inside square brackets, e.g. pattern="[\S]+" or "[a-z\S]".

Common situations: Schemas written with XSD-flavored regex shortcuts; schema authors assuming \S works anywhere; patterns ported from XML Schema validators (like Xerces) that support \S inside classes.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/8f35d1b77850bd25. Report an issue: GitHub.