Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.13] DOCS: Suggest always calling exec with a globals argument and no locals argument (GH-119235)#119239

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 1 commit intopython:3.13frommiss-islington:backport-7e1a130-3.13
May 20, 2024

Conversation

miss-islington
Copy link
Contributor

@miss-islingtonmiss-islington commentedMay 20, 2024
edited by github-actionsbot
Loading

Many users think they want a locals argument for various reasons but they do not
understand that it makes code be treated as a class definition. They do not want
their code treated as a class definition and get surprised. The reason not
to pass locals specifically is that the following code raises aNameError:

exec("""def f():    print("hi")f()def g():    f()g()""", {}, {})

The reason not to leave out globals is as follows:

deft():exec("""def f():    print("hi")f()def g():    f()g()    """)

(cherry picked from commit7e1a130)

Co-authored-by: Hood Chathamroberthoodchatham@gmail.com


📚 Documentation preview 📚:https://cpython-previews--119239.org.readthedocs.build/

…ls argument (pythonGH-119235)Many users think they want a locals argument for various reasons but they do notunderstand that it makes code be treated as a class definition. They do not wanttheir code treated as a class definition and get surprised. The reason notto pass locals specifically is that the following code raises a `NameError`:```pyexec("""def f():    print("hi")f()def g():    f()g()""", {}, {})```The reason not to leave out globals is as follows:```pydef t():    exec("""def f():    print("hi")f()def g():    f()g()    """)```(cherry picked from commit7e1a130)Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
docsDocumentation in the Doc dirskip issueskip news
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@miss-islington@gpshead@hoodmane

[8]ページ先頭

©2009-2025 Movatter.jp