PatternSpec#
- class scikitplot.cleanprompt.PatternSpec(kind, pattern, intent, priority=50, flags=0, validate=None, confidence=1.0, enabled_by_default=True, examples_yes=(), examples_no=(), risk_reason=None)[source]#
One named structural pattern.
- Parameters:
- kindstr
Category label, used to build placeholders. Upper case by convention.
- patternstr
The regular expression source.
- intentstr
What this pattern is for, in one sentence. Reviewed, not decorative.
- priorityint, default=50
Arbitration weight under
PRIORITY_WINSand as a tie-break elsewhere. Higher means more specific.- flagsint, default=0
Flags passed to
re.compile.- validatecallable, optional
validate(match) -> bool. A structural match returningFalseis discarded. Must be pure and total.- confidencefloat, default=1.0
Confidence reported for matches of this pattern.
- enabled_by_defaultbool, default=True
Whether
default_patternsincludes it.- examples_yestuple of str, default=()
Strings that must produce at least one accepted match.
- examples_notuple of str, default=()
Strings that must produce no accepted match.
- risk_reasonstr, optional
Set when the pack accepts this pattern’s backtracking risk on purpose (
risk: accepted), with the reason written beside it. The pattern risk check then lists it as accepted instead of warning.
- Raises:
- PatternError
If
patterndoes not compile, orintentis empty.
- Parameters:
- compiled()[source]#
Return the compiled expression.
- Returns:
- re.Pattern
The compiled pattern.
- Return type:
Notes
Developer notes.
re.compilemaintains its own cache keyed on(pattern, flags), so repeated calls are cheap and no cache is kept here. Holding a compiled object on a frozen dataclass would make the instance unpicklable for no gain.
Gallery examples#
Cleanprompt from Python: Single Calls and Edge Cases