-
Notifications
You must be signed in to change notification settings - Fork 359
Description
I have just spent the last hour fighting with Fava to get it to correctly pass the arguments my hooks expect:
Fava detects if the user wants beangulp-style hooks by looking at the type annotations, however there are several problems with the current implementation:
-
get_annotations(hook_fn)will only work for functions, however one of my hooks is actually a callable object:class MyHook(): def __init__(self, regex_list): self.regex_list = regex_list def __call__(self, extracted, existing) -> list[tuple[str, data.Entries, str, Importer]]: pass
This case is easily fixable by also checking
get_annotations(hook_fn.__call__), however I'm not sure that this covers all possible cases.For now, an easy workaround on my side is to wrap my callable object with a function with the correct return type annotation.
-
The current code assumes that annotations are stringly-typed (uses
"Importer" in annotationas a test), however this is not the case in all instances: I had to addfrom __future__ import annotationsto my file for this test to work. Otherwise the test fails even though the type annotations are present. I guess this could be fixed with"Importer" in str(annotation), but that doesn't feel great.
I can submit a PR if you think the fixes I mentioned are good enough, but the overall approach feels fragile to me, and could break in other scenarios as well. I don't have a better solution though π