|
6 | 6 |
|
7 | 7 | from __future__ import annotations |
8 | 8 |
|
| 9 | +from collections.abc import Sequence |
9 | 10 | from typing import TYPE_CHECKING |
10 | 11 |
|
| 12 | +from libdestruct.backing.resolver import Resolver |
11 | 13 | from libdestruct.common.inflater import Inflater |
12 | 14 |
|
13 | | -if TYPE_CHECKING: # pragma: no cover |
14 | | - from collections.abc import MutableSequence |
| 15 | +if TYPE_CHECKING: # pragma: no cover |
15 | 16 |
|
| 17 | + from libdestruct.common.obj import obj |
16 | 18 |
|
17 | | -def inflater(memory: MutableSequence) -> Inflater: |
| 19 | + |
| 20 | +def inflater(memory: Sequence) -> Inflater: |
18 | 21 | """Return a TypeInflater instance.""" |
| 22 | + if not isinstance(memory, Sequence): |
| 23 | + raise TypeError(f"memory must be a MutableSequence, not {type(memory).__name__}") |
| 24 | + |
19 | 25 | return Inflater(memory) |
| 26 | + |
| 27 | + |
| 28 | +def inflate(item: type, memory: Sequence, address: int | Resolver) -> obj: |
| 29 | + """Inflate a memory-referencing type. |
| 30 | +
|
| 31 | + Args: |
| 32 | + item: The type to inflate. |
| 33 | + memory: The memory view, which can be mutable or immutable. |
| 34 | + address: The address of the object in the memory view. |
| 35 | +
|
| 36 | + Returns: |
| 37 | + The inflated object. |
| 38 | + """ |
| 39 | + if not isinstance(address, int) and not isinstance(address, Resolver): |
| 40 | + raise TypeError(f"address must be an int or a Resolver, not {type(address).__name__}") |
| 41 | + |
| 42 | + return inflater(memory).inflate(item, address) |
0 commit comments