From 25da7aff21846c8df820913ea81d0d3a9c2bd8e4 Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 19 Mar 2021 14:31:04 -0600 Subject: [PATCH] Add uninstall_filter, deprecate uninstallFilter --- docs/overview.rst | 2 +- docs/web3.eth.rst | 12 ++++++++--- newsfragments/1920.feature.rst | 1 + tests/integration/parity/common.py | 8 ++++++-- web3/_utils/module_testing/eth_module.py | 26 ++++++++++++++++++------ web3/eth.py | 3 ++- 6 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 newsfragments/1920.feature.rst diff --git a/docs/overview.rst b/docs/overview.rst index dbebef1287..cf426e1dc6 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -280,7 +280,7 @@ API - :meth:`web3.eth.filter() ` - :meth:`web3.eth.getFilterChanges() ` - :meth:`web3.eth.getFilterLogs() ` -- :meth:`web3.eth.uninstallFilter() ` +- :meth:`web3.eth.uninstall_filter() ` - :meth:`web3.eth.getLogs() ` - :meth:`Contract.events.your_event_name.createFilter() ` - :meth:`Contract.events.your_event_name.build_filter() ` diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index da8fad067d..6a299335c3 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -1097,7 +1097,7 @@ with the filtering API. ] -.. py:method:: Eth.uninstallFilter(self, filter_id) +.. py:method:: Eth.uninstall_filter(self, filter_id) * Delegates to ``eth_uninstallFilter`` RPC Method. @@ -1107,12 +1107,18 @@ with the filtering API. .. code-block:: python >>> filt = web3.eth.filter() - >>> web3.eth.uninstallFilter(filt.filter_id) + >>> web3.eth.uninstall_filter(filt.filter_id) True - >>> web3.eth.uninstallFilter(filt.filter_id) + >>> web3.eth.uninstall_filter(filt.filter_id) False # already uninstalled. +.. py:method:: Eth.uninstallFilter(self, filter_id) + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.eth.Eth.uninstall_filter` + + .. py:method:: Eth.getLogs(filter_params) This is the equivalent of: creating a new diff --git a/newsfragments/1920.feature.rst b/newsfragments/1920.feature.rst new file mode 100644 index 0000000000..8b29fd6e17 --- /dev/null +++ b/newsfragments/1920.feature.rst @@ -0,0 +1 @@ +Add ``eth.uninstall_filter``, deprecate ``eth.uninstallFilter`` diff --git a/tests/integration/parity/common.py b/tests/integration/parity/common.py index 287bcc98c7..88952976a4 100644 --- a/tests/integration/parity/common.py +++ b/tests/integration/parity/common.py @@ -50,9 +50,13 @@ def test_eth_estimateGas_revert_without_msg( def test_eth_getBlockByNumber_pending(self, web3): super().test_eth_getBlockByNumber_pending(web3) - def test_eth_uninstallFilter(self, web3): + def test_eth_uninstall_filter(self, web3): pytest.xfail('eth_uninstallFilter calls to parity always return true') - super().test_eth_uninstallFilter(web3) + super().test_eth_uninstall_filter(web3) + + def test_eth_uninstallFilter_deprecated(self, web3): + pytest.xfail('eth_uninstallFilter calls to parity always return true') + super().test_eth_uninstallFilter_deprecated(web3) @pytest.mark.xfail(reason='Parity is not setup to auto mine') def test_eth_replace_transaction_already_mined(self, web3, unlocked_account): diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 925d92b4ef..c80119b025 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -1245,7 +1245,7 @@ def test_eth_newFilter(self, web3: "Web3") -> None: assert is_list_like(logs) assert not logs - result = web3.eth.uninstallFilter(filter.filter_id) + result = web3.eth.uninstall_filter(filter.filter_id) assert result is True def test_eth_newBlockFilter(self, web3: "Web3") -> None: @@ -1261,7 +1261,7 @@ def test_eth_newBlockFilter(self, web3: "Web3") -> None: # assert is_list_like(logs) # assert not logs - result = web3.eth.uninstallFilter(filter.filter_id) + result = web3.eth.uninstall_filter(filter.filter_id) assert result is True def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None: @@ -1277,7 +1277,7 @@ def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None: # assert is_list_like(logs) # assert not logs - result = web3.eth.uninstallFilter(filter.filter_id) + result = web3.eth.uninstall_filter(filter.filter_id) assert result is True def test_eth_getLogs_without_logs( @@ -1440,14 +1440,28 @@ def test_eth_call_old_contract_state( if pending_call_result != 1: raise AssertionError("pending call result was %d instead of 1" % pending_call_result) - def test_eth_uninstallFilter(self, web3: "Web3") -> None: + def test_eth_uninstallFilter_deprecated(self, web3: "Web3") -> None: filter = web3.eth.filter({}) assert is_string(filter.filter_id) - success = web3.eth.uninstallFilter(filter.filter_id) + with pytest.warns(DeprecationWarning, + match="uninstallFilter is deprecated in favor of uninstall_filter"): + success = web3.eth.uninstallFilter(filter.filter_id) + assert success is True + + with pytest.warns(DeprecationWarning, + match="uninstallFilter is deprecated in favor of uninstall_filter"): + failure = web3.eth.uninstallFilter(filter.filter_id) + assert failure is False + + def test_eth_uninstall_filter(self, web3: "Web3") -> None: + filter = web3.eth.filter({}) + assert is_string(filter.filter_id) + + success = web3.eth.uninstall_filter(filter.filter_id) assert success is True - failure = web3.eth.uninstallFilter(filter.filter_id) + failure = web3.eth.uninstall_filter(filter.filter_id) assert failure is False def test_eth_getTransactionFromBlock_deprecation( diff --git a/web3/eth.py b/web3/eth.py index 60cd4b343d..c5f59208a3 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -615,7 +615,7 @@ def filter_munger( mungers=[default_root_munger], ) - uninstallFilter: Method[Callable[[HexStr], bool]] = Method( + uninstall_filter: Method[Callable[[HexStr], bool]] = Method( RPC.eth_uninstallFilter, mungers=[default_root_munger], ) @@ -691,3 +691,4 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None: getTransactionReceipt = DeprecatedMethod(get_transaction_receipt, 'getTransactionReceipt', 'get_transaction_receipt') + uninstallFilter = DeprecatedMethod(uninstall_filter, 'uninstallFilter', 'uninstall_filter')