coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
277 stars 24 forks source link

Classmethod fails on the uninitialized class object #92

Closed u-tung closed 1 year ago

u-tung commented 1 year ago

version: dev python: 3.10.12

class Foo:
     @multimethod
     def bar(cls, x: str):
         print(cls, str)

     @classmethod # <- only put this @classmethod here on the final definition
     @bar.register
     def _(cls, x: int):
         print(cls, int)

Foo().bar(10) # ok
Foo.bar(10) # DispatchError: ('bar: 0 methods found', (<class 'int'>,), [])
coady commented 1 year ago

classmethod can not be used with register because register returns the original function, not the multimethod. The example has been updated to demonstrate explicitly calling classmethod.

u-tung commented 1 year ago

@coady Thank you for your answer.