Skip to content

Commit

Permalink
Add exception for method calls outside of module instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Jan 15, 2019
1 parent 122ba1a commit b58a3e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/core/method-class/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
5 changes: 5 additions & 0 deletions web3/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b58a3e2

Please sign in to comment.