Skip to content

Commit 339a7b2

Browse files
committed
Bump alysis dependency, relock, and fix ruff errors
1 parent 1871dcc commit 339a7b2

15 files changed

Lines changed: 1224 additions & 860 deletions

docs/changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ Changelog
22
---------
33

44

5+
0.8.2 (in development)
6+
~~~~~~~~~~~~~~~~~~~~~~
7+
8+
Added
9+
^^^^^
10+
11+
- Hash methods for ABI types. (PR_81_)
12+
13+
14+
.. _PR_81: https://github.com/fjarri-eth/pons/pull/81
15+
16+
517
0.8.1 (2024-11-12)
618
~~~~~~~~~~~~~~~~~~
719

pdm.lock

Lines changed: 1130 additions & 822 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pons/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,34 @@
7171
"ContractPanic",
7272
"CycleFallback",
7373
"DeployedContract",
74+
"EVMVersion",
7475
"Either",
7576
"Error",
76-
"EVMVersion",
77-
"LocalProvider",
7877
"Event",
7978
"EventFilter",
8079
"Fallback",
8180
"FallbackProvider",
8281
"FallbackStrategy",
8382
"FallbackStrategyFactory",
8483
"HTTPProvider",
84+
"HTTPProviderServer",
85+
"LocalProvider",
8586
"Method",
8687
"MethodCall",
8788
"MultiMethod",
8889
"Mutability",
8990
"PriorityFallback",
9091
"ProtocolError",
91-
"ProviderError",
9292
"Provider",
93+
"ProviderError",
9394
"Receive",
9495
"RemoteError",
95-
"HTTPProviderServer",
9696
"Signer",
9797
"SnapshotID",
9898
"TransactionFailed",
9999
"Unreachable",
100100
"abi",
101101
"compile_contract_file",
102-
"get_create_address",
103102
"get_create2_address",
103+
"get_create_address",
104104
]

pons/_abi_types.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def _denormalize(self, val: ABIType) -> int:
147147
def __eq__(self, other: object) -> bool:
148148
return isinstance(other, UInt) and self._bits == other._bits
149149

150+
def __hash__(self) -> int:
151+
return hash((type(self), self._bits))
152+
150153

151154
class Int(Type):
152155
"""Corresponds to the Solidity ``int<bits>`` type."""
@@ -183,6 +186,9 @@ def _denormalize(self, val: ABIType) -> int:
183186
def __eq__(self, other: object) -> bool:
184187
return isinstance(other, Int) and self._bits == other._bits
185188

189+
def __hash__(self) -> int:
190+
return hash((type(self), self._bits))
191+
186192

187193
class Bytes(Type):
188194
"""Corresponds to the Solidity ``bytes<size>`` type."""
@@ -199,8 +205,7 @@ def canonical_form(self) -> str:
199205
def _check_val(self, val: Any) -> bytes:
200206
if not isinstance(val, bytes):
201207
raise TypeError(
202-
f"`{self.canonical_form}` must correspond to a bytestring, "
203-
f"got {type(val).__name__}"
208+
f"`{self.canonical_form}` must correspond to a bytestring, got {type(val).__name__}"
204209
)
205210
if self._size is not None and len(val) != self._size:
206211
raise ValueError(f"Expected {self._size} bytes, got {len(val)}")
@@ -236,6 +241,9 @@ def decode_from_topic(self, val: bytes) -> None | bytes:
236241
def __eq__(self, other: object) -> bool:
237242
return isinstance(other, Bytes) and self._size == other._size
238243

244+
def __hash__(self) -> int:
245+
return hash((type(self), self._size))
246+
239247

240248
class AddressType(Type):
241249
"""
@@ -250,8 +258,7 @@ def canonical_form(self) -> str:
250258
def _normalize(self, val: Any) -> str:
251259
if not isinstance(val, Address):
252260
raise TypeError(
253-
f"`address` must correspond to an `Address`-type value, "
254-
f"got {type(val).__name__}"
261+
f"`address` must correspond to an `Address`-type value, got {type(val).__name__}"
255262
)
256263
return val.checksum
257264

@@ -263,6 +270,9 @@ def _denormalize(self, val: ABIType) -> Address:
263270
def __eq__(self, other: object) -> bool:
264271
return isinstance(other, AddressType)
265272

273+
def __hash__(self) -> int:
274+
return hash(type(self))
275+
266276

267277
class String(Type):
268278
"""Corresponds to the Solidity ``string`` type."""
@@ -299,6 +309,9 @@ def decode_from_topic(self, _val: bytes) -> None:
299309
def __eq__(self, other: object) -> bool:
300310
return isinstance(other, String)
301311

312+
def __hash__(self) -> int:
313+
return hash(type(self))
314+
302315

303316
class Bool(Type):
304317
"""Corresponds to the Solidity ``bool`` type."""
@@ -323,6 +336,9 @@ def _denormalize(self, val: ABIType) -> bool:
323336
def __eq__(self, other: object) -> bool:
324337
return isinstance(other, Bool)
325338

339+
def __hash__(self) -> int:
340+
return hash(type(self))
341+
326342

327343
class Array(Type):
328344
"""Corresponds to the Solidity array (``[<size>]``) type."""
@@ -366,6 +382,9 @@ def __eq__(self, other: object) -> bool:
366382
and self._size == other._size
367383
)
368384

385+
def __hash__(self) -> int:
386+
return hash((type(self), self._element_type, self._size))
387+
369388

370389
class Struct(Type):
371390
"""Corresponds to the Solidity struct type."""
@@ -426,6 +445,9 @@ def __eq__(self, other: object) -> bool:
426445
and list(self._fields) == list(other._fields)
427446
)
428447

448+
def __hash__(self) -> int:
449+
return hash((type(self), tuple(self._fields.items())))
450+
429451

430452
_UINT_RE = re.compile(r"uint(\d+)")
431453
_INT_RE = re.compile(r"int(\d+)")

pons/_client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ async def eth_get_transaction_by_hash(self, tx_hash: TxHash) -> None | TxInfo:
329329
# Need an explicit cast, mypy doesn't work with union types correctly.
330330
# See https://github.com/python/mypy/issues/16935
331331
return cast(
332-
None | TxInfo,
332+
"None | TxInfo",
333333
await rpc_call(
334334
self._provider_session,
335335
"eth_getTransactionByHash",
@@ -343,7 +343,7 @@ async def eth_get_transaction_receipt(self, tx_hash: TxHash) -> None | TxReceipt
343343
# Need an explicit cast, mypy doesn't work with union types correctly.
344344
# See https://github.com/python/mypy/issues/16935
345345
return cast(
346-
None | TxReceipt,
346+
"None | TxReceipt",
347347
await rpc_call(
348348
self._provider_session,
349349
"eth_getTransactionReceipt",
@@ -505,7 +505,7 @@ async def eth_get_block_by_hash(
505505
# Need an explicit cast, mypy doesn't work with union types correctly.
506506
# See https://github.com/python/mypy/issues/16935
507507
return cast(
508-
None | BlockInfo,
508+
"None | BlockInfo",
509509
await rpc_call(
510510
self._provider_session,
511511
"eth_getBlockByHash",
@@ -522,7 +522,7 @@ async def eth_get_block_by_number(
522522
# Need an explicit cast, mypy doesn't work with union types correctly.
523523
# See https://github.com/python/mypy/issues/16935
524524
return cast(
525-
None | BlockInfo,
525+
"None | BlockInfo",
526526
await rpc_call(
527527
self._provider_session,
528528
"eth_getBlockByNumber",
@@ -552,7 +552,7 @@ async def broadcast_transfer(
552552
max_tip = min(Amount.gwei(1), max_gas_price)
553553
nonce = await self.eth_get_transaction_count(signer.address, BlockLabel.PENDING)
554554
tx = cast(
555-
dict[str, JSON],
555+
"dict[str, JSON]",
556556
unstructure(
557557
Type2Transaction(
558558
chain_id=chain_id,
@@ -622,7 +622,7 @@ async def deploy(
622622
max_tip = min(Amount.gwei(1), max_gas_price)
623623
nonce = await self.eth_get_transaction_count(signer.address, BlockLabel.PENDING)
624624
tx = cast(
625-
dict[str, JSON],
625+
"dict[str, JSON]",
626626
unstructure(
627627
Type2Transaction(
628628
chain_id=chain_id,
@@ -680,7 +680,7 @@ async def broadcast_transact(
680680
max_tip = min(Amount.gwei(1), max_gas_price)
681681
nonce = await self.eth_get_transaction_count(signer.address, BlockLabel.PENDING)
682682
tx = cast(
683-
dict[str, JSON],
683+
"dict[str, JSON]",
684684
unstructure(
685685
Type2Transaction(
686686
chain_id=chain_id,
@@ -854,7 +854,7 @@ async def iter_blocks(self, poll_interval: int = 1) -> AsyncIterator[BlockHash]:
854854
for block_hash in block_hashes:
855855
# We can't ensure it statically, since `eth_getFilterChanges` return type depends
856856
# on the filter passed to it.
857-
yield cast(BlockHash, block_hash)
857+
yield cast("BlockHash", block_hash)
858858
await anyio.sleep(poll_interval)
859859

860860
async def iter_pending_transactions(self, poll_interval: int = 1) -> AsyncIterator[TxHash]:
@@ -865,7 +865,7 @@ async def iter_pending_transactions(self, poll_interval: int = 1) -> AsyncIterat
865865
for tx_hash in tx_hashes:
866866
# We can't ensure it statically, since `eth_getFilterChanges` return type depends
867867
# on the filter passed to it.
868-
yield cast(TxHash, tx_hash)
868+
yield cast("TxHash", tx_hash)
869869
await anyio.sleep(poll_interval)
870870

871871
async def iter_events(
@@ -891,5 +891,5 @@ async def iter_events(
891891
for log_entry in log_entries:
892892
# We can't ensure it statically, since `eth_getFilterChanges` return type depends
893893
# on the filter passed to it.
894-
yield event_filter.decode_log_entry(cast(LogEntry, log_entry))
894+
yield event_filter.decode_log_entry(cast("LogEntry", log_entry))
895895
await anyio.sleep(poll_interval)

pons/_contract_abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def _add_method(self, method: Method) -> None:
437437
def with_method(self, method: Method) -> "MultiMethod":
438438
"""Returns a new ``MultiMethod`` with the given method included."""
439439
new_mm = MultiMethod(*self._methods.values())
440-
new_mm._add_method(method) # noqa: SLF001
440+
new_mm._add_method(method)
441441
return new_mm
442442

443443
def __call__(self, *args: Any, **kwds: Any) -> "MethodCall":

pons/_fallback_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def __init__(self, weights: list[int]):
3939
def get_provider_order(self) -> list[int]:
4040
if self._counter == self._weights[0]:
4141
self._counter = 0
42-
self._providers = self._providers[1:] + [self._providers[0]]
43-
self._weights = self._weights[1:] + [self._weights[0]]
42+
self._providers = [*self._providers[1:], self._providers[0]]
43+
self._weights = [*self._weights[1:], self._weights[0]]
4444

4545
self._counter += 1
4646
return list(self._providers)

pons/_http_provider_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def parse_request(request: JSON) -> tuple[JSON, str, list[JSON]]:
19-
request = cast(dict[str, JSON], request)
19+
request = cast("dict[str, JSON]", request)
2020
request_id = request["id"]
2121
method = request["method"]
2222
if not isinstance(method, str):
@@ -77,7 +77,7 @@ def make_app(provider: Provider) -> ASGIFramework:
7777

7878
# We don't have a typing package shared between Starlette and Hypercorn,
7979
# so this will have to do
80-
return cast(ASGIFramework, app)
80+
return cast("ASGIFramework", app)
8181

8282

8383
class HTTPProviderServer:

pons/_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def rpc(self, method: str, *args: JSON) -> JSON:
129129

130130
if not isinstance(response_json, Mapping):
131131
raise InvalidResponse(f"RPC response must be a dictionary, got: {response_json}")
132-
response_json = cast(Mapping[str, JSON], response_json)
132+
response_json = cast("Mapping[str, JSON]", response_json)
133133

134134
# Note that the Eth-side errors (e.g. transaction having been reverted)
135135
# will have the HTTP status 200, so we are checking for the "error" field first.

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ compiler = [
2828
"py-solc-x>=2",
2929
]
3030
local-provider = [
31-
"alysis>=0.5.0",
31+
"alysis>=0.6.0",
3232
"starlette",
3333
"hypercorn",
3434
]
@@ -98,14 +98,10 @@ ignore = [
9898
"C408",
9999
# It's never a problem unless you mutate function arguments (which is rarely a good idea).
100100
"B008",
101-
# The type of `self` is derived automatically.
102-
"ANN101",
103101
# We use `Any` quite a bit because we need to accept a lot of third-party unnormalized input.
104102
"ANN401",
105103
# The return type of `__init__` is derived automatically.
106104
"ANN204",
107-
# The type of `cls` in classmethods is derived automatically.
108-
"ANN102",
109105
# Doesn't mesh well with the way `black` puts the final parenthesis on a separate line
110106
# in functions with one parameter and a long argument.
111107
"COM812",

0 commit comments

Comments
 (0)