|
36 | 36 | ContractABI, |
37 | 37 | Error, |
38 | 38 | EventFilter, |
| 39 | + FieldValues, |
39 | 40 | UnknownError, |
40 | 41 | ) |
41 | 42 | from ._provider import Provider, ProviderError, ProviderSession |
@@ -156,10 +157,10 @@ class ContractError(Exception): |
156 | 157 | error: Error |
157 | 158 | """The recognized ABI Error object.""" |
158 | 159 |
|
159 | | - data: dict[str, Any] | tuple[Any, ...] |
| 160 | + data: FieldValues |
160 | 161 | """The unpacked error data, corresponding to the ABI.""" |
161 | 162 |
|
162 | | - def __init__(self, error: Error, decoded_data: dict[str, Any] | tuple[Any, ...]): |
| 163 | + def __init__(self, error: Error, decoded_data: FieldValues): |
163 | 164 | super().__init__(error, decoded_data) |
164 | 165 | self.error = error |
165 | 166 | self.data = decoded_data |
@@ -189,14 +190,16 @@ def decode_contract_error( |
189 | 190 | except UnknownError: |
190 | 191 | return ProviderError(exc) |
191 | 192 |
|
192 | | - # These errors have named fields, so `decoded_data` is expected to be a dictionary. |
193 | | - # The assertions are there for `mypy`'s sake. |
194 | 193 | if error == PANIC_ERROR: |
195 | | - assert isinstance(decoded_data, dict) # noqa: S101 |
196 | | - return ContractPanic.from_code(decoded_data["code"]) |
| 194 | + # If `resolve_error()` finished successfully, |
| 195 | + # `code` will be present in `decoded_data` |
| 196 | + # since it is declared as a field in the PANIC_ERROR |
| 197 | + return ContractPanic.from_code(decoded_data.as_dict["code"]) |
197 | 198 | if error == LEGACY_ERROR: |
198 | | - assert isinstance(decoded_data, dict) # noqa: S101 |
199 | | - return ContractLegacyError(decoded_data["message"]) |
| 199 | + # If `resolve_error()` finished successfully, |
| 200 | + # `message` will be present in `decoded_data` |
| 201 | + # since it is declared as a field in the PANIC_ERROR |
| 202 | + return ContractLegacyError(decoded_data.as_dict["message"]) |
200 | 203 |
|
201 | 204 | return ContractError(error, decoded_data) |
202 | 205 | return ProviderError(exc) |
@@ -519,7 +522,7 @@ async def transact( |
519 | 522 | amount: None | Amount = None, |
520 | 523 | gas: None | int = None, |
521 | 524 | return_events: None | Sequence[BoundEvent] = None, |
522 | | - ) -> dict[BoundEvent, list[dict[str, Any]]]: |
| 525 | + ) -> dict[BoundEvent, list[FieldValues]]: |
523 | 526 | """ |
524 | 527 | Transacts with the contract using a prepared method call. |
525 | 528 | If ``gas`` is ``None``, the required amount of gas is estimated first, |
@@ -594,7 +597,7 @@ async def iter_events( |
594 | 597 | poll_interval: int = 1, |
595 | 598 | from_block: Block = BlockLabel.LATEST, |
596 | 599 | to_block: Block = BlockLabel.LATEST, |
597 | | - ) -> AsyncIterator[dict[str, Any]]: |
| 600 | + ) -> AsyncIterator[FieldValues]: |
598 | 601 | """ |
599 | 602 | Yields decoded log entries produced by the filter. |
600 | 603 | The fields that were hashed when converted to topics (that is, fields of reference types) |
|
0 commit comments