Skip to content

Commit 29f0d3b

Browse files
authored
Deprecate eth.get_uncle* methods (#3685)
* Cherry-pick efe41ef * Deprecate get_uncle* methods * Update docs * Deprecate async get_uncle* methods
1 parent c197826 commit 29f0d3b

File tree

9 files changed

+68
-20
lines changed

9 files changed

+68
-20
lines changed

docs/web3.eth.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ The following methods are available on the ``web3.eth`` namespace.
398398
399399
.. py:method:: Eth.get_uncle_by_block(block_identifier, uncle_index)
400400
401+
.. warning:: Deprecated. Will be removed in v8.
402+
401403
* Delegates to ``eth_getUncleByBlockHashAndIndex`` or
402404
``eth_getUncleByBlockNumberAndIndex`` RPC methods
403405

@@ -444,6 +446,8 @@ The following methods are available on the ``web3.eth`` namespace.
444446
445447
.. py:method:: Eth.get_uncle_count(block_identifier)
446448
449+
.. warning:: Deprecated. Will be removed in v8.
450+
447451
* Delegates to ``eth_getUncleCountByBlockHash`` or
448452
``eth_getUncleCountByBlockNumber`` RPC methods
449453

newsfragments/3683.deprecation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate eth.get_uncle* methods. Will be removed in v8.

tests/core/utilities/test_abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ def test_get_event_abi(event_name: str, input_args: Sequence[ABIComponent]) -> N
829829

830830
with pytest.warns(
831831
DeprecationWarning,
832-
match="get_event_abi is deprecated in favor of get_abi_element",
832+
match="get_event_abi is deprecated: use get_abi_element instead",
833833
):
834834
assert (
835835
get_event_abi(contract_abi, event_name, input_names) == expected_event_abi

web3/_utils/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def deprecated_for(replace_message: str) -> Callable[..., Any]:
4343
"""
4444
Decorate a deprecated function, with info about what to use instead, like:
4545
46-
@deprecated_for("to_bytes()")
46+
@deprecated_for("use to_bytes() instead")
4747
def toAscii(arg):
4848
...
4949
"""
@@ -52,7 +52,7 @@ def decorator(to_wrap: TFunc) -> TFunc:
5252
@functools.wraps(to_wrap)
5353
def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
5454
warnings.warn(
55-
f"{to_wrap.__name__} is deprecated in favor of {replace_message}",
55+
f"{to_wrap.__name__} is deprecated: {replace_message}",
5656
category=DeprecationWarning,
5757
stacklevel=2,
5858
)

web3/_utils/module_testing/eth_module.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,19 +2221,31 @@ async def test_eth_getBlockTransactionCountByHash_block_with_txn(
22212221
async def test_eth_getUncleCountByBlockHash(
22222222
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
22232223
) -> None:
2224-
uncle_count = await async_w3.eth.get_uncle_count(async_empty_block["hash"])
2224+
with pytest.warns(
2225+
DeprecationWarning,
2226+
match=r"get_uncle_count is deprecated: all get_uncle\* "
2227+
r"methods will be removed in v8",
2228+
):
2229+
uncle_count = await async_w3.eth.get_uncle_count(async_empty_block["hash"])
22252230

2226-
assert is_integer(uncle_count)
2227-
assert uncle_count == 0
2231+
assert is_integer(uncle_count)
2232+
assert uncle_count == 0
22282233

22292234
@pytest.mark.asyncio
22302235
async def test_eth_getUncleCountByBlockNumber(
22312236
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
22322237
) -> None:
2233-
uncle_count = await async_w3.eth.get_uncle_count(async_empty_block["number"])
2238+
with pytest.warns(
2239+
DeprecationWarning,
2240+
match=r"get_uncle_count is deprecated: all get_uncle\* "
2241+
r"methods will be removed in v8",
2242+
):
2243+
uncle_count = await async_w3.eth.get_uncle_count(
2244+
async_empty_block["number"]
2245+
)
22342246

2235-
assert is_integer(uncle_count)
2236-
assert uncle_count == 0
2247+
assert is_integer(uncle_count)
2248+
assert uncle_count == 0
22372249

22382250
@pytest.mark.asyncio
22392251
async def test_eth_getBlockTransactionCountByNumber_block_with_txn(
@@ -2843,18 +2855,24 @@ def test_eth_getBlockTransactionCountByNumber_block_with_txn(
28432855
def test_eth_getUncleCountByBlockHash(
28442856
self, w3: "Web3", empty_block: BlockData
28452857
) -> None:
2846-
uncle_count = w3.eth.get_uncle_count(empty_block["hash"])
2858+
with pytest.warns(
2859+
DeprecationWarning, match=r"All get_uncle\* methods have been deprecated"
2860+
):
2861+
uncle_count = w3.eth.get_uncle_count(empty_block["hash"])
28472862

2848-
assert is_integer(uncle_count)
2849-
assert uncle_count == 0
2863+
assert is_integer(uncle_count)
2864+
assert uncle_count == 0
28502865

28512866
def test_eth_getUncleCountByBlockNumber(
28522867
self, w3: "Web3", empty_block: BlockData
28532868
) -> None:
2854-
uncle_count = w3.eth.get_uncle_count(empty_block["number"])
2869+
with pytest.warns(
2870+
DeprecationWarning, match=r"All get_uncle\* methods have been deprecated"
2871+
):
2872+
uncle_count = w3.eth.get_uncle_count(empty_block["number"])
28552873

2856-
assert is_integer(uncle_count)
2857-
assert uncle_count == 0
2874+
assert is_integer(uncle_count)
2875+
assert uncle_count == 0
28582876

28592877
def test_eth_get_code(
28602878
self, w3: "Web3", math_contract_address: ChecksumAddress

web3/eth/async_eth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
from web3._utils.compat import (
4040
Unpack,
4141
)
42+
from web3._utils.decorators import (
43+
deprecated_for,
44+
)
4245
from web3._utils.fee_utils import (
4346
async_fee_history_priority_fee,
4447
)
@@ -669,6 +672,7 @@ async def sign_typed_data(
669672
mungers=[default_root_munger],
670673
)
671674

675+
@deprecated_for("all get_uncle* methods will be removed in v8")
672676
async def get_uncle_count(self, block_identifier: BlockIdentifier) -> int:
673677
return await self._get_uncle_count(block_identifier)
674678

web3/eth/eth.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
Web3ValueError,
7070
)
7171
from web3.method import (
72+
DeprecatedMethod,
7273
Method,
7374
default_root_munger,
7475
)
@@ -566,26 +567,38 @@ def get_proof_munger(
566567
# eth_getUncleCountByBlockHash
567568
# eth_getUncleCountByBlockNumber
568569

569-
get_uncle_count: Method[Callable[[BlockIdentifier], int]] = Method(
570+
_get_uncle_count: Method[Callable[[BlockIdentifier], int]] = Method(
570571
method_choice_depends_on_args=select_method_for_block_identifier(
571572
if_predefined=RPC.eth_getUncleCountByBlockNumber,
572573
if_hash=RPC.eth_getUncleCountByBlockHash,
573574
if_number=RPC.eth_getUncleCountByBlockNumber,
574575
),
575576
mungers=[default_root_munger],
576577
)
578+
get_uncle_count = DeprecatedMethod(
579+
_get_uncle_count,
580+
old_name="_get_uncle_count",
581+
new_name="get_uncle_count",
582+
msg="All get_uncle* methods have been deprecated",
583+
)
577584

578585
# eth_getUncleByBlockHashAndIndex
579586
# eth_getUncleByBlockNumberAndIndex
580587

581-
get_uncle_by_block: Method[Callable[[BlockIdentifier, int], Uncle]] = Method(
588+
_get_uncle_by_block: Method[Callable[[BlockIdentifier, int], Uncle]] = Method(
582589
method_choice_depends_on_args=select_method_for_block_identifier(
583590
if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
584591
if_hash=RPC.eth_getUncleByBlockHashAndIndex,
585592
if_number=RPC.eth_getUncleByBlockNumberAndIndex,
586593
),
587594
mungers=[default_root_munger],
588595
)
596+
get_uncle_by_block = DeprecatedMethod(
597+
_get_uncle_by_block,
598+
old_name="_get_uncle_by_block",
599+
new_name="get_uncle_by_block",
600+
msg="All get_uncle* methods have been deprecated",
601+
)
589602

590603
def replace_transaction(
591604
self, transaction_hash: _Hash32, new_transaction: TxParams

web3/method.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,25 @@ def process_params(
241241

242242
class DeprecatedMethod:
243243
def __init__(
244-
self, method: Method[Callable[..., Any]], old_name: str, new_name: str
244+
self,
245+
method: Method[Callable[..., Any]],
246+
old_name: Optional[str] = None,
247+
new_name: Optional[str] = None,
248+
msg: Optional[str] = None,
245249
) -> None:
246250
self.method = method
247251
self.old_name = old_name
248252
self.new_name = new_name
253+
self.msg = msg
249254

250255
def __get__(
251256
self, obj: Optional["Module"] = None, obj_type: Optional[Type["Module"]] = None
252257
) -> Any:
258+
message = f"{self.old_name} is deprecated in favor of {self.new_name}"
259+
if self.msg is not None:
260+
message = self.msg
253261
warnings.warn(
254-
f"{self.old_name} is deprecated in favor of {self.new_name}",
262+
message,
255263
category=DeprecationWarning,
256264
stacklevel=2,
257265
)

web3/utils/abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def check_if_arguments_can_be_encoded(
682682
)
683683

684684

685-
@deprecated_for("get_abi_element")
685+
@deprecated_for("use get_abi_element instead")
686686
def get_event_abi(
687687
abi: ABI,
688688
event_name: str,

0 commit comments

Comments
 (0)