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_WINS and 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 returning False is discarded. Must be pure and total.

confidencefloat, default=1.0

Confidence reported for matches of this pattern.

enabled_by_defaultbool, default=True

Whether default_patterns includes 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 pattern does not compile, or intent is empty.

Parameters:
compiled()[source]#

Return the compiled expression.

Returns:
re.Pattern

The compiled pattern.

Return type:

Pattern

Notes

Developer notes. re.compile maintains 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.

confidence: float = 1.0#
enabled_by_default: bool = True#
examples_no: tuple[str, ...] = ()#
examples_yes: tuple[str, ...] = ()#
flags: int = 0#
intent: str[source]#
kind: str[source]#
pattern: str[source]#
priority: int = 50#
risk_reason: str | None = None#
validate: Callable[[Match], bool] | None = None#