openrig.naming.types module
Type definitions for the naming system.
Defines all types used internally by the naming package:
- Config types (used by
rules.py): RuleConfig: raw deserialized configuration for a single token rule.GlobalRules: global constraints applied to every fully-built name.
- Token value types (used by
manager.py): TokenValue: accepted raw input for a token before normalization.TokenData: canonical post-normalization form (alwaysstrvalues).
- Rule protocol (used by
manager.py): RuleValidator:Protocolthat every rule type must satisfy.
- Concrete rule implementations (used by
rules.py,manager.py): RegexRule: validates a token value against a regular expression.ListRule: validates a token value against a fixed set of allowed values.CallableRule: delegates validation to an arbitrary callable.ConcreteRule: union of all concrete rule types.
- class openrig.naming.types.RuleConfig(type: str, value: str | list[str] | None = None, sources: list[str] | None = None, module: str | None = None)[source]
Bases:
objectRaw deserialized configuration for a single token rule.
Intermediate representation populated from
naming/config.json.rules.pyconverts each instance into aConcreteRule.- type
Rule type:
"regex","list","from_enums", or"callable".- Type:
str
- value
Primary payload — pattern string, list of values, or dotted import path, depending on
type.- Type:
str | list[str] | None
- sources
Enum class names to aggregate. Only for
"from_enums".- Type:
list[str] | None
- module
Dotted module path where
sourcesare defined. Only for"from_enums". Defaults to"openrig.constants".- Type:
str | None
- type: str
- value: str | list[str] | None = None
- sources: list[str] | None = None
- module: str | None = None
- class openrig.naming.types.GlobalRules(max_length: int, forbidden_patterns: list[str] = <factory>, separator_rule: ~openrig.naming.types.RuleConfig | None = None)[source]
Bases:
objectGlobal constraints applied to every fully-built name.
- max_length
Maximum allowed character length for any built name.
- Type:
int
- forbidden_patterns
Substrings that must not appear in any built name.
- Type:
list[str]
- separator_rule
Optional
RuleConfigconstraining valid separators.- Type:
- max_length: int
- forbidden_patterns: list[str]
- separator_rule: RuleConfig | None = None
- class openrig.naming.types.RuleValidator(*args, **kwargs)[source]
Bases:
ProtocolProtocol for all token-level validation rules.
Any object that implements
validateandto_regex_patternsatisfies this protocol.Example
>>> class MyRule: ... def validate(self, value: str) -> bool: ... return value.isalpha() ... def to_regex_pattern(self) -> str: ... return r"[a-zA-Z]+"
- class openrig.naming.types.RegexRule(pattern: str)[source]
Bases:
objectA rule that validates a token value against a regular expression.
- pattern
The regex pattern string. Anchors
^/$are optional;validatealways performs a full match.- Type:
str
Example
>>> rule = RegexRule(pattern=r"^[a-z][a-zA-Z0-9]*$") >>> rule.validate("armUpper") True >>> rule.validate("Arm Upper") False
- pattern: str
- class openrig.naming.types.ListRule(allowed: frozenset[str])[source]
Bases:
objectA rule that validates a token value against a fixed set of allowed values.
- allowed
A frozenset of accepted string values.
- Type:
frozenset[str]
Example
>>> rule = ListRule(allowed=frozenset({"l", "r", "c", "m"})) >>> rule.validate("l") True >>> rule.validate("left") False
- allowed: frozenset[str]
- class openrig.naming.types.CallableRule(func: object, name: str)[source]
Bases:
objectA rule that delegates validation to an arbitrary callable.
The callable must accept a single
strargument and returnbool. Because callable rules are opaque to the regex engine,to_regex_patternreturns a catch-all pattern; validation must be performed separately viavalidate.- func
The validation callable. Typed as
objectto avoid hashability issues; narrowed at call site.- Type:
object
- name
A human-readable label used in error messages and
__repr__.- Type:
str
Example
>>> rule = CallableRule(func=str.isalpha, name="alpha_only") >>> rule.validate("arm") True >>> rule.validate("arm1") False
- func: object
- name: str