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

Surprising statement pull-out in multi-item with #2605

Closed
Kodiologist opened this issue Sep 17, 2024 · 0 comments · Fixed by #2606
Closed

Surprising statement pull-out in multi-item with #2605

Kodiologist opened this issue Sep 17, 2024 · 0 comments · Fixed by #2606

Comments

@Kodiologist
Copy link
Member

Consider:

(import
  contextlib [nullcontext])

(with [a (nullcontext)  b (do a (nullcontext))])

This raises NameError: name 'a' is not defined. How this happens is clear enough to the experienced Hy programmer, but that it happens at all can be surprising considering that e.g.

(for [a [1]  b (do a [1])])

works fine. And the Python language reference specifies that

With more than one item, the context managers are processed as if multiple with statements were nested:

with A() as a, B() as b:
    SUITE

is semantically equivalent to:

with A() as a:
    with B() as b:
        SUITE

So it's surprising that this equivalency doesn't hold for Hy.

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

Successfully merging a pull request may close this issue.

1 participant