type_bridge.typeql.annotations¶
annotations
¶
Shared TypeQL annotation formatting utilities.
This module centralizes the formatting logic for TypeQL annotations to avoid duplication across the codebase.
format_card_annotation
¶
Format a @card(min..max) annotation string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_val
|
int | None
|
Minimum cardinality (None means unspecified, defaults to 0) |
required |
max_val
|
int | None
|
Maximum cardinality (None means unbounded) |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Formatted annotation string like "@card(1..5)" or "@card(2..)", |
str | None
|
or None if both min and max are None. |
Examples:
>>> format_card_annotation(1, 5)
'@card(1..5)'
>>> format_card_annotation(2, None)
'@card(2..)'
>>> format_card_annotation(0, 1)
'@card(0..1)'
>>> format_card_annotation(None, None)
None
Source code in type_bridge/typeql/annotations.py
format_type_annotations
¶
Format type-level annotations (@abstract, @independent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
abstract
|
bool
|
Whether to include @abstract annotation |
False
|
independent
|
bool
|
Whether to include @independent annotation |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of annotation strings (may be empty) |
Examples:
>>> format_type_annotations(abstract=True)
['@abstract']
>>> format_type_annotations(abstract=True, independent=True)
['@abstract', '@independent']
>>> format_type_annotations()
[]