This had me frustrated for ages until I thought to look at closed issues on the GitHub and realized what I was doing wrong. When I read "last" in the documentation, I thought last per function (because decorators read inside out, ie "last" being the first decorator listed). Not sure if anyone else would be as dumb as me, but maybe couldn't hurt to put a classmethod/staticmethod example in the documentation with multiple methods.
class Foo:
@classmethod # <- don't do that
@multimethod
def bar(cls, x: str):
print(x)
@classmethod # <- or that
@bar.register(str, str)
def bar(cls, x: str, y: str):
pass
@classmethod # <- only put this @classmethod here on the final definition
@bar.register(int, int)
def bar(cls, x: int, y: int):
print(x+1)
This had me frustrated for ages until I thought to look at closed issues on the GitHub and realized what I was doing wrong. When I read "last" in the documentation, I thought last per function (because decorators read inside out, ie "last" being the first decorator listed). Not sure if anyone else would be as dumb as me, but maybe couldn't hurt to put a classmethod/staticmethod example in the documentation with multiple methods.