-
Notifications
You must be signed in to change notification settings - Fork 371
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
we should have better documentation and error message for with-decorator
#1624
Comments
It shouldn't be, or else something is wrong. Instead of |
Fair enough, so the problem remaining is better error message. |
Playing with it a bit, I think there is a discrepancy here. How can we translate this Python code into Hy code? import functools
def the_answer(f):
@functools.wraps(f)
def decorated():
return 42
return decorated
@the_answer
def tell_me():
return 0
tell_me() # -> 42 Literal translation (sans the (import functools)
(defn the-answer [f]
(with-decorator (functools.wraps f)
(defn decorated []
42)))
(with-decorator the-answer
(defn tell-me [] 0))
(tell-me) ;; raises "TypeError: 'NoneType' object is not callable" I know sometime ago, Maybe the true literal translation with |
Yeah, you need to put
|
docmebro, maybe? Cause the proposed way is not lispy (for my own definition of lispy, that is 😄). |
No, nesting
This prints:
|
My fault. I mistakenly thought that because Thanks for your clarification. |
Right, it has to be a special form because it directly modifies attributes of AST nodes. |
Scenario 1
It works on anonymous functions before (for example, 0.12.1), I believe decorating
(fn ...)
is useful sometimes. In python, there is no 'auto return', no multi-line lambda anddef
is not an expression, so we must use a named function, and the name is usually of no importance beside being used to be returned. To me, it looks good enough to have anfn
as the last form.For Example:
I think we should support
fn
(as before) here, if not, we should mention that in the documentation, and using a better error message,fn
is obviously a function.Scenario 2
Here, feeding a type that's already been defined (not on the spot) raises an exception, which is reasonable BTW, but we should have more descriptive error message,
with-decorator
supports classes, too, and the wording implies only functions can be used here.The text was updated successfully, but these errors were encountered: