Skip to content

Commit 26e18d4

Browse files
committed
docs: describe Python value translation
1 parent 6d0de0a commit 26e18d4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/py-design-001.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ Each bullet below represents a low-level operation translating a single `sys.mon
6060
- Track every file path referenced; copy each into the trace directory under `files/`.
6161
- Record `VariableName`, `Type`, and `Value` entries when variables are inspected or logged.
6262

63+
## Value Translation and Recording
64+
- Maintain a type registry that maps Python `type` objects to `runtime_tracing` `Type` entries and assigns new `type_id` values on first encounter.
65+
- Convert primitives (`int`, `float`, `bool`, `None`, `str`) directly to their corresponding `ValueRecord` variants.
66+
- Encode `bytes` and `bytearray` as `Raw` records containing base64 text to preserve binary data.
67+
- Represent lists and sets as `Sequence` records and tuples as `Tuple` records, converting each element recursively.
68+
- Serialize dictionaries as a `Sequence` of two-element `Tuple` records for key/value pairs to avoid fixed field layouts.
69+
- For objects with accessible attributes, emit a `Struct` record with sorted field names; fall back to `Raw` with `repr(obj)` when inspection is unsafe.
70+
- Track object identities to detect cycles and reuse `Reference` records with `id(obj)` for repeated structures.
71+
6372
## Shutdown
6473
- On `stop_tracing`, call `sys.monitoring.set_events` with `NO_EVENTS` for the tool ID.
6574
- Unregister callbacks and free the tool ID with `sys.monitoring.free_tool_id`.

0 commit comments

Comments
 (0)