Repository: ethereum/web3.py

Issue:
Deprecate `miner` namespace support and tests

### What was wrong?

Geth removed support for their `miner` API since it's no longer needed after The Merge ™️ . See: https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-miner


### How can it be fixed?

Add deprecation warnings to the methods within the miner namespace, and change the tests to check for the deprecation warnings. We can then either remove the methods as Geth stops supporting these, or wait until v7 to remove.



Discussion:

Resolving patch:
diff --git a/web3/_utils/miner.py b/web3/_utils/miner.py
--- a/web3/_utils/miner.py
+++ b/web3/_utils/miner.py
@@ -10,6 +10,7 @@
     RPC,
 )
 from web3.method import (
+    DeprecatedMethod,
     Method,
     default_root_munger,
 )
@@ -18,49 +19,74 @@
     Wei,
 )
 
-make_dag: Method[Callable[[BlockNumber], bool]] = Method(
+#
+# The Geth client deprecated the miner namespace.
+#
+
+_make_dag: Method[Callable[[BlockNumber], bool]] = Method(
     RPC.miner_makeDag,
     mungers=[default_root_munger],
 )
 
+make_dag = DeprecatedMethod(
+    _make_dag, "make_dag", msg="All mining methods have been deprecated"
+)
 
-set_extra: Method[Callable[[str], bool]] = Method(
+_set_extra: Method[Callable[[str], bool]] = Method(
     RPC.miner_setExtra,
     mungers=[default_root_munger],
 )
 
+set_extra = DeprecatedMethod(
+    _set_extra, "set_extra", msg="All mining methods have been deprecated"
+)
 
-set_etherbase: Method[Callable[[ChecksumAddress], bool]] = Method(
+_set_etherbase: Method[Callable[[ChecksumAddress], bool]] = Method(
     RPC.miner_setEtherbase,
     mungers=[default_root_munger],
 )
 
+set_etherbase = DeprecatedMethod(
+    _set_etherbase, "set_etherbase", msg="All mining methods have been deprecated"
+)
 
-set_gas_price: Method[Callable[[Wei], bool]] = Method(
+_set_gas_price: Method[Callable[[Wei], bool]] = Method(
     RPC.miner_setGasPrice,
     mungers=[default_root_munger],
 )
 
+set_gas_price = DeprecatedMethod(
+    _set_gas_price, "set_gas_price", msg="All mining methods have been deprecated"
+)
 
-start: Method[Callable[[int], bool]] = Method(
+_start: Method[Callable[[int], bool]] = Method(
     RPC.miner_start,
     mungers=[default_root_munger],
 )
 
+start = DeprecatedMethod(_start, "start", msg="All mining methods have been deprecated")
 
-stop: Method[Callable[[], bool]] = Method(
+_stop: Method[Callable[[], bool]] = Method(
     RPC.miner_stop,
     is_property=True,
 )
 
+stop = DeprecatedMethod(_stop, "stop", msg="All mining methods have been deprecated")
 
-start_auto_dag: Method[Callable[[], bool]] = Method(
+_start_auto_dag: Method[Callable[[], bool]] = Method(
     RPC.miner_startAutoDag,
     is_property=True,
 )
 
+start_auto_dag = DeprecatedMethod(
+    _start_auto_dag, "start_auto_dag", msg="All mining methods have been deprecated"
+)
 
-stop_auto_dag: Method[Callable[[], bool]] = Method(
+_stop_auto_dag: Method[Callable[[], bool]] = Method(
     RPC.miner_stopAutoDag,
     is_property=True,
 )
+
+stop_auto_dag = DeprecatedMethod(
+    _stop_auto_dag, "stop_auto_dag", msg="All mining methods have been deprecated"
+)
diff --git a/web3/method.py b/web3/method.py
--- a/web3/method.py
+++ b/web3/method.py
@@ -214,17 +214,26 @@ def process_params(self, module: "Module", *args: Any, **kwargs: Any) -> Tuple[
 
 class DeprecatedMethod:
     def __init__(
-        self, method: Method[Callable[..., Any]], old_name: str, new_name: str
+        self,
+        method: Method[Callable[..., Any]],
+        old_name: str,
+        new_name: Optional[str] = None,
+        msg: Optional[str] = None,
     ) -> None:
         self.method = method
         self.old_name = old_name
         self.new_name = new_name
+        self.msg = msg
 
     def __get__(
         self, obj: Optional["Module"] = None, obj_type: Optional[Type["Module"]] = None
     ) -> Any:
+        message = f"{self.old_name} is deprecated in favor of {self.new_name}"
+        if self.msg is not None:
+            message = self.msg
+
         warnings.warn(
-            f"{self.old_name} is deprecated in favor of {self.new_name}",
+            message,
             category=DeprecationWarning,
         )
         return self.method.__get__(obj, obj_type)


Test patch:
diff --git a/tests/core/txpool-module/test_txpool_content.py b/tests/core/txpool-module/test_txpool_content.py
--- a/tests/core/txpool-module/test_txpool_content.py
+++ b/tests/core/txpool-module/test_txpool_content.py
@@ -1,3 +1,4 @@
+import pytest
 import random
 
 from web3._utils.threads import (
@@ -8,7 +9,8 @@
 def test_txpool_content(web3_empty):
     web3 = web3_empty
 
-    web3.geth.miner.stop()
+    with pytest.warns(DeprecationWarning):
+        web3.geth.miner.stop()
 
     with Timeout(60) as timeout:
         while web3.eth.hashrate or web3.eth.mining:
diff --git a/tests/core/txpool-module/test_txpool_inspect.py b/tests/core/txpool-module/test_txpool_inspect.py
--- a/tests/core/txpool-module/test_txpool_inspect.py
+++ b/tests/core/txpool-module/test_txpool_inspect.py
@@ -1,3 +1,4 @@
+import pytest
 import random
 
 from web3._utils.threads import (
@@ -8,7 +9,8 @@
 def test_txpool_inspect(web3_empty):
     web3 = web3_empty
 
-    web3.geth.miner.stop()
+    with pytest.warns(DeprecationWarning):
+        web3.geth.miner.stop()
 
     with Timeout(60) as timeout:
         while web3.eth.hashrate or web3.eth.mining:
diff --git a/web3/_utils/module_testing/module_testing_utils.py b/web3/_utils/module_testing/module_testing_utils.py
--- a/web3/_utils/module_testing/module_testing_utils.py
+++ b/web3/_utils/module_testing/module_testing_utils.py
@@ -1,6 +1,7 @@
 from collections import (
     deque,
 )
+import pytest
 import time
 from typing import (
     TYPE_CHECKING,
@@ -61,14 +62,15 @@
 
 
 def mine_pending_block(w3: "Web3") -> None:
-    timeout = 10
-
-    w3.geth.miner.start()  # type: ignore
-    start = time.time()
-    while time.time() < start + timeout:
-        if len(w3.eth.get_block("pending")["transactions"]) == 0:
-            break
-    w3.geth.miner.stop()  # type: ignore
+    with pytest.warns(DeprecationWarning):
+        timeout = 10
+
+        w3.geth.miner.start()  # type: ignore
+        start = time.time()
+        while time.time() < start + timeout:
+            if len(w3.eth.get_block("pending")["transactions"]) == 0:
+                break
+        w3.geth.miner.stop()  # type: ignore
 
 
 def assert_contains_log(