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

fix: try blocks delete context variable afterwards, but marimo still considers them refs or defs if used #1571

Merged
merged 7 commits into from
Jun 7, 2024

Conversation

dmadisetti
Copy link
Collaborator

📝 Summary

previously

try:
   1 / 0
except Exception as e:
   f = e
   e = 2
refs(), defs()

Would give ref=e, def=e,f. At first glance, this seems fine- but "e" is scoped to the try block and is deleted afterwards, so the correct solution is ref=[], def=[f]

Note in the case

e = 7
try:
   1 / 0
except Exception as e:
   f = e
   e = 2
   print("woops")

e is no longer set if the except block triggers, but because it was set outside of the block, ref=, def=e,f is correct

🔍 Description of Changes

Added an ObscuredScope context to remove Name references if they are obscured by the try block + added some unit tests

Your PR will be reviewed more quickly if you can figure out the right person to tag with @ -->
@akshayka OR @mscolnick

Copy link

vercel bot commented Jun 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 2:12am
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 2:12am

Copy link
Contributor

@mscolnick mscolnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find and fix!

@mscolnick mscolnick merged commit 428b688 into marimo-team:main Jun 7, 2024
27 checks passed
@dmadisetti dmadisetti deleted the fix-try-scope branch June 7, 2024 14:32
@dmadisetti dmadisetti mentioned this pull request Jun 9, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants