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

Make sure the ~PY sigil does not trigger an unused variable warning #6

Merged
merged 1 commit into from
Feb 23, 2025

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
@@ -290,6 +290,9 @@ defmodule Pythonx do
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

@@ -290,6 +290,9 @@ defmodule Pythonx do
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