-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Clarify the required behaviour of locals() #62160
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
Comments
As proposed at [1], I would like to tighten up the definition of locals so that defining enum members programmatically is officially supported behaviour. I'll come up with a patch soonish. [1] http://mail.python.org/pipermail/python-dev/2013-May/125917.html |
Since "soonish" turned out to be "4 years and counting", copying in the specifics of the proposal in from the old python-dev thread:
It would be a lot simpler to document the expected behaviour at function scope if locals() were to be updated to return a true snapshot (i.e. a copy of f_locals, rather than a direct reference), with direct access to the shared locals reference requiring going through the frame attribute. That way, trace functions could still modify local variables (since they use |
I've tried thinking though a few scenarios, and I think I'm +1 (or at least |
Guido: perhaps I should run this update through the PEP process? Even though the actual proposed change is only to a pretty obscure edge case (having multiple concurrent live references to the result of locals() for a function namespace), the extra visibility should help developers of alternative implementations be clear on what is happening. |
Yeah, I think a short PEP would be helpful here. |
Status update: I've posted an initial PR to bpo-30744 that relies on the trace hook semantic change proposed in the PEP to resolve the trace hook/cell reference incompatibility reported there. That provides confidence that it really is only the semantics of *trace hooks* that we need to change, rather than anything about locals() or frame.f_locals in general. So the next steps will be to do a final editing pass on the current PEP to account for the reference implementation, and then send it to python-dev for official review and pronouncement. |
Nathaniel raised a valid concern about the draft PEP over in https://bugs.python.org/issue30744#msg302475, so I've been considering whether or not it would be possible to make the write-through proxy idea work without introducing other problems. I think I have a workable design concept for that approach now: https://bugs.python.org/issue30744#msg304099 So the next step will be to see if that actually does work as well as I think it will, and if so, update the PEP accordingly. |
|
Yeah, this part is done (since it's just about the Python level API of |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: