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

Decorating anonymous functions is inconsistent #2271

Closed
allison-casey opened this issue May 6, 2022 · 3 comments · Fixed by #2270
Closed

Decorating anonymous functions is inconsistent #2271

allison-casey opened this issue May 6, 2022 · 3 comments · Fixed by #2270
Labels

Comments

@allison-casey
Copy link
Contributor

allison-casey commented May 6, 2022

Attempting to decorate an fn that can compile down to a lambda fails, but it won't fail if the fn contains statements that force compilation to an anonymous def

=> (with-decorator cache (fn [x] x))
Traceback (most recent call last):
  File "stdin-ecb69bbf92e18e5e87b4bc8c6fd3222c5969d4a8", line 1, in <module>
    (with-decorator cache (fn [x] x))
  File "<stdin>", line 1
    (with-decorator cache (fn [x] x))
                          ^
hy.errors.HySyntaxError: Decorated a non-function
=> (with-decorator cache (fn [x] (print 1) x))
@cache
def _hy_anon_var_2(x):
    print(1)
    return x
_hy_anon_var_2

I think it makes the most sense to force the anon def when an fn uses a decorator like it already does when it contains statements or type annotations.

@Kodiologist
Copy link
Member

This should be immediately closed by #2270, since there will no longer be a way to decorate a fn.

@allison-casey
Copy link
Contributor Author

then it should be noted in NEWS as a breaking change probably

@Kodiologist
Copy link
Member

I think that's implied by "with-decorator and #@ have been removed in favor of decorator lists (see below)" and the description of decorator lists only mentioning defn and defclass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants