Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Improve typing for decorators that change signature #80

Open
timmens opened this issue Jun 12, 2024 · 0 comments
Open

ENH: Improve typing for decorators that change signature #80

timmens opened this issue Jun 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@timmens
Copy link
Member

timmens commented Jun 12, 2024

In lcm.functools, we provide functions allow_only_kwargs and allow_args. These change the parameter kind of the function arguments.

They work as follows:

def f(a, /, *, b):
   return a + b

f(a=1, b=1)  # error because a is positional-only
f(1, 1)  # error because b is keyword-only

allow_only_kwargs(f)(a=1, b=1)  # no error
allow_args(f)(1, 1)  # no error

However, the type annotations of the product of these decorators are not optimal. For example, we currently cannot signal that the function returned by allow_only_kwargs has only keyword-only arguments but is otherwise identical to the input function.

Goal

  • General: Add more information through typing
  • Explicit: Add information that decorated functions are identical to the input functions except for the changed parameter kind.

Links

@timmens timmens added the enhancement New feature or request label Jun 12, 2024
@timmens timmens mentioned this issue Jun 12, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant