diff --git a/tests/core/method-class/test_method.py b/tests/core/method-class/test_method.py index 1e8b39f5c3..62533cd67b 100644 --- a/tests/core/method-class/test_method.py +++ b/tests/core/method-class/test_method.py @@ -270,7 +270,7 @@ def dummy_w3(): def test_munger_class_method_access_raises_friendly_error(): - with pytest.raises(Exception): + with pytest.raises(TypeError): FakeModule.method(1, 2) diff --git a/web3/method.py b/web3/method.py index c341fd4ae2..e6e25cc5bc 100644 --- a/web3/method.py +++ b/web3/method.py @@ -83,6 +83,11 @@ def __init__( self.formatter_lookup_fn = formatter_lookup_fn or get_default_formatters def __get__(self, obj=None, obj_type=None): + if obj is None: + raise TypeError( + "Direct calls to methods are not supported. " + "Methods must be called from an module instance, " + "usually attached to a web3 instance.") return obj.retrieve_caller_fn(self) @property