Skip to content

Commit b58a3e2

Browse files
committed
Add exception for method calls outside of module instance
1 parent 122ba1a commit b58a3e2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/core/method-class/test_method.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def dummy_w3():
270270

271271

272272
def test_munger_class_method_access_raises_friendly_error():
273-
with pytest.raises(Exception):
273+
with pytest.raises(TypeError):
274274
FakeModule.method(1, 2)
275275

276276

web3/method.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def __init__(
8383
self.formatter_lookup_fn = formatter_lookup_fn or get_default_formatters
8484

8585
def __get__(self, obj=None, obj_type=None):
86+
if obj is None:
87+
raise TypeError(
88+
"Direct calls to methods are not supported. "
89+
"Methods must be called from an module instance, "
90+
"usually attached to a web3 instance.")
8691
return obj.retrieve_caller_fn(self)
8792

8893
@property

0 commit comments

Comments
 (0)