Skip to content

Commit cfe99ee

Browse files
jensensclaude
andcommitted
Fix TYPE_MAPPING.md to reflect actual implementation
- Remove @inst marker (produced but never decoded, dead code path) - Clarify timezone handling: fixed offsets in ISO string vs named TZ with @tz key - Update marker priority to single-key vs multi-key distinction - Remove stale phase reference from backward compat section Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c7b56c9 commit cfe99ee

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

TYPE_MAPPING.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ Python: `datetime(2025, 6, 15, 12, 30, 45)`
9999

100100
**Timezone handling:**
101101

102+
Fixed-offset timezones are embedded directly in the ISO 8601 string. Named
103+
timezones (pytz, zoneinfo) use a separate `@tz` key to preserve the zone
104+
name for exact roundtrip fidelity. These two forms are mutually exclusive.
105+
102106
| Timezone Source | JSON Form |
103107
|---|---|
104108
| Naive (no tz) | `{"@dt": "2025-01-01T00:00:00"}` |
@@ -303,14 +307,6 @@ callable and arguments for roundtripping.
303307
}
304308
```
305309

306-
### `@inst` — Anonymous instance
307-
308-
For BUILD operations where the class couldn't be identified.
309-
310-
```json
311-
{"@inst": {"@state": ...}}
312-
```
313-
314310
### `@pkl` — Raw pickle escape hatch
315311

316312
Base64-encoded pickle fragment for types that can't be represented in JSON.
@@ -323,25 +319,21 @@ this marker.
323319

324320
## Marker Priority
325321

326-
When decoding JSON back to pickle, markers are checked in this order:
327-
328-
1. `@t` (tuple)
329-
2. `@b` (bytes)
330-
3. `@bi` (bigint)
331-
4. `@d` (non-string-key dict)
332-
5. `@set` (set)
333-
6. `@fset` (frozenset)
334-
7. `@ref` (persistent reference)
335-
8. `@pkl` (raw pickle)
336-
9. `@dt`, `@date`, `@time`, `@td`, `@dec`, `@uuid` (known types)
337-
10. `@cls` + `@s` (instance)
338-
11. `@cls` alone (global reference)
339-
12. `@reduce` (generic reduce)
340-
13. Plain JSON object → Python dict
322+
When decoding JSON back to pickle, single-key marker dicts are checked first,
323+
then multi-key patterns:
324+
325+
**Single-key markers:**
326+
`@t`, `@b`, `@bi`, `@d`, `@set`, `@fset`, `@ref`, `@pkl`,
327+
`@dt`, `@date`, `@time`, `@td`, `@dec`, `@uuid`, `@reduce`
328+
329+
**Multi-key markers:**
330+
`@cls` + `@s` (instance with BTree detection), `@dt` + `@tz` (tz-aware datetime)
331+
332+
**Fallback:** Plain JSON object → Python dict
341333

342334
## Backward Compatibility
343335

344336
If JSON data was stored using the generic `@reduce` format for types that now
345-
have dedicated markers (e.g., datetime stored as `@reduce` before Phase 3),
346-
the decoder still handles `@reduce` correctly. The new markers only affect the
347-
forward direction (pickle → JSON).
337+
have dedicated markers (e.g., datetime stored as `@reduce` before the known
338+
type handlers were added), the decoder still handles `@reduce` correctly.
339+
The new markers only affect the forward direction (pickle → JSON).

0 commit comments

Comments
 (0)