Repository navigation
Commit 55f5cdd
fix(msgpack): raise DecodeError for unhashable map keys (#1209)
## Problem
`msgspec.msgpack.decode` currently raises a bare `TypeError` when a
MessagePack map or `ext` is used as a map key. That escapes the
documented `DecodeError` contract, so `except msgspec.DecodeError` does
not catch it.
## Fix
In `mpack_decode_dict`, translate `TypeError` from `PyDict_SetItem` into
`DecodeError`. Other errors (e.g. OOM) are left unchanged.
`mpack_decode_frozendict` already goes through this path.
## Tests
Adds coverage for map/ext keys (`818001`, `878048`, `8bd4ec5c03`) and
keeps the hashable array-key control (`819001` → `{(): 1}`).
Fixes #1208
---------
Co-authored-by: Tseluiko Aleksandr <[email protected]>1 parent b2d1b7a commit 55f5cdd
2 files changed
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16290 | 16290 | | |
16291 | 16291 | | |
16292 | 16292 | | |
16293 | | - | |
| 16293 | + | |
| 16294 | + | |
| 16295 | + | |
| 16296 | + | |
| 16297 | + | |
| 16298 | + | |
| 16299 | + | |
| 16300 | + | |
| 16301 | + | |
16294 | 16302 | | |
| 16303 | + | |
16295 | 16304 | | |
16296 | 16305 | | |
16297 | 16306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
542 | 557 | | |
543 | 558 | | |
544 | 559 | | |
| |||
0 commit comments