Closed vnmabus closed 7 months ago
It's trying to do an instance check because of the Protocol subclass. While I work on a fix, a workaround would be to use @ runtime_checkable
.
Thanks for the report.
It's trying to do an instance check because of the Protocol subclass. While I work on a fix, a workaround would be to use
@ runtime_checkable
.
Note that the superclass may come from a different package, and in that case it would not be possible to use runtime_checkable
.
Also, it would be awesome if there were a way to annotate method
with a non-runtime-checkable protocol Kk
in the example instead of Any
, for typing purposes.
Fixed in main now.
Also, it would be awesome if there were a way to annotate
method
with a non-runtime-checkable protocolKk
in the example instead ofAny
, for typing purposes.
I don't think that's possible, in that a type either supports issubclass
or it doesn't. runtime_checkable
could also be called explicitly (though it modifies the type).
@multimethod.multidispatch
def method(a: runtime_checkable(Kk)):
return a.kk()
I don't think that's possible, in that a type either supports
issubclass
or it doesn't.runtime_checkable
could also be called explicitly (though it modifies the type).
But as multidispatch
is the base case, it shouldn't be necessary to check its types with isinstance
, should it?
But as
multidispatch
is the base case, it shouldn't be necessary to check its types withisinstance
, should it?
Interesting. singledispatch originally didn't support annotations at all, so of course the base implementation wasn't "registered". Even now the example shows the base unannotated (and only later clarifies that it behaves as object
would).
I wonder if this is a case of an implementation detail becoming a feature. Anyway, multidispatch
is supposed to be consistent, but I think the current dispatch behavior will have to be deprecated first.
In v1.11.1. Thanks for the report.
I have several multimethods which I use with concrete (non-protocol) classes subclassing a particular
Protocol
. For example:This used to return
'concrete'
in version 1.10.However, in the most recent version (1.11) this produces the following exception instead: