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

evaluate namespaces recursively, and function namespaces, too #2

Merged
merged 2 commits into from
May 18, 2023

Conversation

carljm
Copy link
Owner

@carljm carljm commented May 18, 2023

This recursively finds functions and classes from the top-level namespace and evaluates both.

For functions we do this by inserting a return locals() as the last statement in every function, so we can call it to get its namespace.

@carljm
Copy link
Owner Author

carljm commented May 18, 2023

Already found a bug using this, with a function body containing a = [1 for a in []].

@carljm carljm requested a review from JelleZijlstra May 18, 2023 16:06
evalserver.py Outdated Show resolved Hide resolved
@carljm
Copy link
Owner Author

carljm commented May 18, 2023

(The bug I found is python/cpython#104615)

@@ -236,6 +236,7 @@ def statements():
st.from_type(ast.Global),
st.from_type(ast.Expr),
st.from_type(ast.FunctionDef),
st.from_type(ast.Name),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would just generate statements of the form a, right? Not sure why that's useful.

Copy link
Owner Author

Choose a reason for hiding this comment

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

In the simplified reproducer for python/cpython#104602 a simple b after the comprehension would expose the bug. (In your form it was a print(b) but the print isn't necessary.) So it seems useful to allow these to be generated?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's true. One concern is that this will just throw NameError in most cases, making the run tests less useful. But it can still help catch scoping bugs.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Although with only two allowed names, the chance of NameError decreases some? You may be right, I think we will need to observe some actual runs.

@carljm carljm merged commit a39bfc9 into main May 18, 2023
@JelleZijlstra JelleZijlstra deleted the funcstoo branch May 18, 2023 17:04
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