Skip to content

Add comment to subtle dataclass code#96133

Merged
ericvsmith merged 1 commit into
python:mainfrom
hauntsaninja:dataclass-comment
Oct 4, 2022
Merged

Add comment to subtle dataclass code#96133
ericvsmith merged 1 commit into
python:mainfrom
hauntsaninja:dataclass-comment

Conversation

@hauntsaninja
Copy link
Copy Markdown
Contributor

In the PR that made this change, 1st1 left a "note to self: add a
comment explaining this". This comment was never added.
https://github.com/python/cpython/pull/9518/files#r280608117

I was reading this code and it wasn't obvious to me why we weren't
exec-ing directly into locals. So I got to learn something new :-)
https://docs.python.org/3/reference/executionmodel.html#interaction-with-dynamic-features

In the PR that made this change, 1st1 left a "note to self: add a
comment explaining this". This comment was never added.
https://github.com/python/cpython/pull/9518/files#r280608117

I was reading this code and it wasn't obvious to me why we weren't
exec-ing directly into locals. So I got to learn something new :-)
https://docs.python.org/3/reference/executionmodel.html#interaction-with-dynamic-features
Comment thread Lib/dataclasses.py
# Free variables in exec are resolved in the global namespace.
# The global namespace we have is user-provided, so we can't modify it for
# our purposes. So we put the things we need into locals and introduce a
# scope to allow the function we're creating to close over them.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks reasonable to me, but I'll wait to hear from @1st1

@ericvsmith ericvsmith merged commit 72b5a55 into python:main Oct 4, 2022
@hauntsaninja hauntsaninja deleted the dataclass-comment branch October 5, 2022 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants