|
| 1 | +"""Type aliases for JSONLT. |
| 2 | +
|
| 3 | +This module contains ONLY TypeAlias definitions for JSON and key types. |
| 4 | +It exists to break circular imports between _exceptions.py, _json.py, and _keys.py: |
| 5 | +- _exceptions.py needs JSONObject and Key for ConflictError |
| 6 | +- _json.py needs ParseError, LimitError from _exceptions.py |
| 7 | +- _keys.py needs InvalidKeyError, LimitError from _exceptions.py |
| 8 | +
|
| 9 | +By placing the type aliases here with no dependencies on other JSONLT modules, |
| 10 | +all modules can safely import from _types.py. |
| 11 | +""" |
| 12 | + |
| 13 | +from typing import TypeAlias |
| 14 | + |
| 15 | +# JSON type definitions per RFC 8259 |
| 16 | +# Using string annotations for forward references to avoid runtime | issues |
| 17 | +JSONPrimitive: TypeAlias = "str | int | float | bool | None" |
| 18 | +"""A JSON primitive value: string, number, boolean, or null.""" |
| 19 | + |
| 20 | +JSONArray: TypeAlias = "list[JSONValue]" |
| 21 | +"""A JSON array containing any JSON values.""" |
| 22 | + |
| 23 | +JSONObject: TypeAlias = "dict[str, JSONValue]" |
| 24 | +"""A JSON object mapping string keys to JSON values.""" |
| 25 | + |
| 26 | +JSONValue: TypeAlias = "JSONPrimitive | JSONArray | JSONObject" |
| 27 | +"""Any JSON value: primitive, array, or object.""" |
| 28 | + |
| 29 | +# Key type definitions per JSONLT specification |
| 30 | +KeyElement: TypeAlias = "str | int" |
| 31 | +"""A key element is a string or integer that may appear in a tuple key.""" |
| 32 | + |
| 33 | +Key: TypeAlias = "str | int | tuple[str | int, ...]" |
| 34 | +"""A key identifies a record within a table. |
| 35 | +
|
| 36 | +A key is one of: |
| 37 | +- A string |
| 38 | +- An integer in the range [-(2^53)+1, (2^53)-1] |
| 39 | +- A tuple of key elements (non-empty, max 16 elements) |
| 40 | +""" |
| 41 | + |
| 42 | +KeySpecifier: TypeAlias = "str | tuple[str, ...]" |
| 43 | +"""A key specifier defines how to extract a key from a record. |
| 44 | +
|
| 45 | +A key specifier is one of: |
| 46 | +- A string naming a single field |
| 47 | +- A tuple of strings naming multiple fields (for compound keys) |
| 48 | +""" |
0 commit comments