From 8920d550480491a6af455b53c056b3eaf75a3111 Mon Sep 17 00:00:00 2001 From: Felipe Selmo Date: Wed, 5 Jan 2022 11:54:50 -0700 Subject: [PATCH] Changes from comments on PR #2288 - Add a test to make sure a tuple with a single module class still works for backwards compatibility. - Take out the docstring examples for `attach_module()` and leave them only in the docs. The consensus is that lengthy docstrings reiterating what is in the documentation would just crowd out our files and make the code harder to read. Instead, we should opt for brief yet useful despritions in the method docstrings. --- tests/core/utilities/test_attach_modules.py | 5 +++++ web3/main.py | 22 --------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/tests/core/utilities/test_attach_modules.py b/tests/core/utilities/test_attach_modules.py index 9f0fd3f79c..36cb8a563a 100644 --- a/tests/core/utilities/test_attach_modules.py +++ b/tests/core/utilities/test_attach_modules.py @@ -53,6 +53,11 @@ def test_attach_modules(): assert w3.geth.admin.start_ws() is True +def test_attach_single_module_as_tuple(): + w3 = Web3(EthereumTesterProvider(), modules={'eth': (MockEth,)}) + assert w3.eth.block_number() == 42 + + def test_attach_modules_multiple_levels_deep(): mods = { "eth": MockEth, diff --git a/web3/main.py b/web3/main.py index 5e38b2b00d..685b7e0f48 100644 --- a/web3/main.py +++ b/web3/main.py @@ -339,28 +339,6 @@ def attach_module( """ Attach a module to the `Web3` instance. Modules should inherit from the `web3.module.Module` class. - - Attaching a simple module: - - >>> w3.attach_module('module1', ModuleClass1) - >>> w3.module1.return_zero - 0 - - Attaching a module with submodules: - - >>> w3.attach_module( - ... 'module2', - ... (ModuleClass2, { - ... 'submodule1': ModuleClass3, - ... 'submodule2': (ModuleClass4, { - ... 'submodule2a': ModuleClass5, - ... }) - ... }) - ... ) - >>> w3.module2.submodule1.return_one - 1 - >>> w3.module2.submodule2.submodule2a.return_two - 2 """ attach_modules(self, {module_name: module})