Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

beangulp-style hook detection is very fragile #2179

Open
Labels

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:

  1. 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.

  2. The current code assumes that annotations are stringly-typed (uses "Importer" in annotation as a test), however this is not the case in all instances: I had to add from __future__ import annotations to 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 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /