Types#
nlql.types —— 类型系统:TypeTag 枚举(TEXT / NUMBER / DATE 等)+ 函数 Signature(arity 校验)+ 操作数强转(as_number / as_date,含快速拒绝优化)。
types
#
NLQL type system: type tags, function signatures, and custom type registration.
__all__
module-attribute
#
TypeHandler
dataclass
#
Parser + optional comparator for a user-registered type.
parse converts a raw string (from DATE '...' or metadata) into the
runtime value used in comparisons. compare overrides the default
compare_values when non-None, receiving (left, right, op).
TypeTag
#
Bases: StrEnum
Coarse value types flowing through query evaluation.
Signature
dataclass
#
Declared argument and return types of a registered function.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
args
|
tuple[TypeTag, ...]
|
Expected argument types, in order. |
必需 |
returns
|
TypeTag
|
Result type. |
必需 |
variadic
|
bool
|
When |
False
|
arity_ok
#
get_type_handler
#
get_type_handler(name: str, type_handlers: dict[str, TypeHandler] | None = None) -> TypeHandler | None
Look up a registered TypeHandler by name (case-insensitive). Checks the optional instance-level dict first, then the global registry.
源代码位于: src/nlql/types/core.py
register_type
#
register_type(name: str, handler: TypeHandler | None = None, *, registry: dict[str, TypeHandler] | None = None) -> Any
Register a custom type. Two modes:
- Direct:
register_type("EMAIL", TypeHandler(parse=...)) - Decorator:
@register_type("EMAIL")on a class (with parse/compare methods) or a bare function (used as parse).