From e6ccb2ea183ff33d422703b750ab65325e05f36a Mon Sep 17 00:00:00 2001 From: Kyle Bowman Date: Sat, 16 Mar 2024 16:09:37 -0400 Subject: [PATCH] Add idea about dispatching Protocols --- develop.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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... -- 2.39.5