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

exec inside a function #48697

Closed
beazley mannequin opened this issue Nov 27, 2008 · 3 comments
Closed

exec inside a function #48697

beazley mannequin opened this issue Nov 27, 2008 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@beazley
Copy link
Mannequin

beazley mannequin commented Nov 27, 2008

BPO 4447
Nosy @birkenfeld

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:

assignee = None
closed_at = <Date 2008-11-27.17:47:21.056>
created_at = <Date 2008-11-27.17:35:01.827>
labels = ['interpreter-core', 'type-bug']
title = 'exec inside a function'
updated_at = <Date 2008-11-27.18:07:18.779>
user = 'https://bugs.python.org/beazley'

bugs.python.org fields:

activity = <Date 2008-11-27.18:07:18.779>
actor = 'beazley'
assignee = 'none'
closed = True
closed_date = <Date 2008-11-27.17:47:21.056>
closer = 'georg.brandl'
components = ['Interpreter Core']
creation = <Date 2008-11-27.17:35:01.827>
creator = 'beazley'
dependencies = []
files = []
hgrepos = []
issue_num = 4447
keywords = []
message_count = 3.0
messages = ['76508', '76509', '76511']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'beazley']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4447'
versions = ['Python 3.0']

@beazley
Copy link
Mannequin Author

beazley mannequin commented Nov 27, 2008

Is the following code valid Python 3 or not?

def foo():
    x = 1
    exec("x = 42")
    print(x)    # Prints 1  (exec has no effect)

I know there are a variety of issues surrounding exec(), function
bodies, and other matters. Just wondering if this sort of thing is now
forbidden or not.

@beazley beazley mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 27, 2008
@birkenfeld
Copy link
Member

It is "valid" Python 3 and the lack of an effect on the local is correct.

From Python 3 on, "exec" is a function and therefore lacks the special
magic properties it had in Python 2 that made it possible execute the
code "as if it just was written there".

In effect, what exec() modifies here is similar to what locals()
returns: a mere copy of the local namespace.

@beazley
Copy link
Mannequin Author

beazley mannequin commented Nov 27, 2008

For what it's worth, I hope this behavior gets well-documented. Thanks.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant