I have a method dispatch decorator with three registered functions. One dispatches on int
, which works fine. The second dispatched on a custom type, also works fine. The third is also a custom type, but the Class is wrapped with the lru_cache
decorator.
(To make things a little more complicated, the class is instantiated in a roundabout way via a methoddispatch on the __call__
method of another class.)
@lru_cache(maxsize=None, typed=True)
class QualifiedInterval:
# stuff that works
Inside the Pitch class:
@oph_utils.method_dispatch
def augmented(self, other):
raise NotImplementedError
@augmented.register(int)
def _(self, other):
return "works fine"
@augmented.register(Interval)
def _(self, other):
return "works fine too"
@augmented.register(QualifiedInterval)
def _(self, other):
return "only works if QualifiedInterval class does NOT have lru_cache"
(There's a lot more going on, but this is the bits that don't work.)
Basically - if I have lru_cache, and pass a QualifiedInterval into the function, it does not dispatch and raises NotImplementedError. If I comment out the cache decorator, it works. And manual type checking at the REPL shows the same type ("QualifiedInterval") either way. I've tried calling the command that created the QualifiedInterval several different ways, and tried assigning it to a variable. Still doesn't work. I've tried doing explicit typechecking in the Augmented function. The typecheck fails there as well, if caching is enabled.