From: Kyle Bowman Date: Sat, 16 Mar 2024 20:09:37 +0000 (-0400) Subject: Add idea about dispatching Protocols X-Git-Tag: v0.1.0~9 X-Git-Url: https://git.rocketbowman.com/?a=commitdiff_plain;h=e6ccb2ea183ff33d422703b750ab65325e05f36a;p=proto.git Add idea about dispatching Protocols --- diff --git a/develop.md b/develop.md index d786017..d2a2262 100644 --- a/develop.md +++ b/develop.md @@ -85,6 +85,15 @@ There are two problems: * Maybe there is a way to define a default implentation of an ABC or a Protocol? * (Promising) Maybe we can cop out. If it's a Protocol, dispatch to a proto-defined hook that passes the buck to the function writer. I.e. add a placeholder "type" to arg_specs. That "type" requires the user to handle the initializer themselves. +I think I can catch protocols thusly: + +``` python +elif hasattr(prm.annotation, 'is_protocol' and prm.annotation._is_protocol): + do_thing() +``` + +You can use `prm.annotation.__abstractmethods__` to determine what methods need to be defined. + ### Parser definition vs Runtime arguments * If you look through Union and define the parser based on the first type...