Skip to content

Commit

Permalink
feat: see methods from the bound function (#193)
Browse files Browse the repository at this point in the history
* feat: see methods from the bound function

Signed-off-by: nstarman <[email protected]>

* test: add test for the dispatcher.

Signed-off-by: nstarman <[email protected]>

---------

Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman authored Nov 15, 2024
1 parent ba3a974 commit 463acd9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plum/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,8 @@ def wrapped_method(*args, **kw_args):
# extended, so unwrapping is likely never desired.

return wrapped_method

@property
def methods(self) -> List[Signature]:
"""list[:class:`.signature.Signature`]: All available methods."""
return self._f.methods
14 changes: 14 additions & 0 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def g(x: float):
assert dispatch.classes[b]["g"].methods[0].signature == Sig(float, precedence=1)


def test_bound_function_attributes():
"""Test the attributes on a bound function."""
dispatch = Dispatcher()

class A:
@dispatch
def f(self, x: int):
pass

# The 'methods' should point to those of the underlying object.
assert A().f.methods is A.f.methods
assert A().f.methods is A().f._f.methods


def test_dispatch_multi():
dispatch = Dispatcher()

Expand Down

0 comments on commit 463acd9

Please sign in to comment.