]> git.rocketbowman.com Git - proto.git/commitdiff
Add idea about dispatching Protocols
authorKyle Bowman <kyle+github@rocketbowman.com>
Sat, 16 Mar 2024 20:09:37 +0000 (16:09 -0400)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sat, 16 Mar 2024 20:09:37 +0000 (16:09 -0400)
develop.md

index d786017d317cace188cea36800906b86848d611b..d2a2262af9982e8c8c1a7e6936e510f3de122f8e 100644 (file)
@@ -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...