Skip to content

Conversation

jonatanklosko
Copy link
Member

When using ~PY in a module body (in a script), assigning Python variables results in unused variables warning, because the sigil always assigns the corresponding Elixir variables, regardless if they are used later.

@jonatanklosko jonatanklosko merged commit a89aa68 into main Feb 23, 2025
9 checks passed
@jonatanklosko jonatanklosko deleted the jk-unused-var branch February 23, 2025 10:54

assignments =
for name <- defined do
quote do
Copy link
Contributor

Choose a reason for hiding this comment

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

After taking a look at Elixir's source, I also think we can get the same behaviour by marking it as generated:

quote generated: true do

assignments =
for name <- defined do
quote do
unquote({String.to_atom(name), [], nil}) = Map.get(globals, unquote(name), nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Or even:

{String.to_atom(name), [generated: true], nil}

Copy link
Member Author

Choose a reason for hiding this comment

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

Glorious, pushed to main, thank you!

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.

2 participants