-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
[Feature Request] @beartype + functools.partial
support
#373
Comments
FWIW I promise I don't actually write code like the above example. A pattern that is used a lot in jax is something like @beartype
@partial(jax.jit, static_argnames=["length"])
def fn(a, length=2):
return a + jnp.ones(length)
fn(1) i.e. to partially apply arguments to a decorator before wrapping. My double partial was a lazy proxy for that (since jit leads to an error anyway), but perhaps I chose a bad proxy, since this seems to work from beartype import beartype
from functools import partial
def add_decorator(fn, add):
return lambda *args, **kwargs: fn(*args, **kwargs) + add
@beartype
@partial(add_decorator, add=5)
def fn(a):
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This feature request comes courtesy @danielward27 at issue #368, who astutely noted that the
@beartype
decorator currently fails to supportfunctools.partial
objects. Notably, this questionable minimal example coercing thefunctools.partial
class into a decorator:...currently raises this mostly unreadable exception:
Just thinking about supporting this makes @leycec vomit all over himself. 🤮
The text was updated successfully, but these errors were encountered: