From 874ae5c68e491de6c8de0a055b6f14ab96df5022 Mon Sep 17 00:00:00 2001 From: Marc Garreau Date: Wed, 11 May 2022 11:42:09 -0600 Subject: [PATCH] add docs for attach_methods (#2465) --- docs/web3.main.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/web3.main.rst b/docs/web3.main.rst index f85840c62d..2d404860e8 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -416,6 +416,26 @@ These internal modules inherit from the ``web3.module.Module`` class which give web3.py library. +Custom Methods +~~~~~~~~~~~~~~ + +You may add or overwrite methods within any module using the ``attach_methods`` function. +To create a property instead, set ``is_property`` to ``True``. + +.. code-block:: python + + >>> w3.eth.attach_methods({ + ... 'example_method': Method( + ... 'eth_example', + ... mungers=[...], + ... request_formatters=[...], + ... result_formatters=[...], + ... is_property=False, + ... ), + ... }) + >>> w3.eth.example_method() + + External Modules ~~~~~~~~~~~~~~~~