Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Commitfda3291
DOCS: Suggest always calling exec with a globals argument and no locals argument (GH-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>
1 parenta6b873f commitfda3291
1 file changed
+7
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
608 | 608 | | |
609 | 609 | | |
610 | 610 | | |
611 | | - | |
612 | | - | |
613 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
614 | 618 | | |
615 | 619 | | |
616 | 620 | | |
| |||
0 commit comments
Comments
(0)