Skip to content

Commit

Permalink
Changes from comments on PR #2288
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
fselmo committed Jan 5, 2022
1 parent 1190d9d commit 8920d55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
5 changes: 5 additions & 0 deletions tests/core/utilities/test_attach_modules.py
Expand Up @@ -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,
Expand Down
22 changes: 0 additions & 22 deletions web3/main.py
Expand Up @@ -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})

Expand Down

0 comments on commit 8920d55

Please sign in to comment.