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() ignores scope. #87614

Closed
Keepun mannequin opened this issue Mar 9, 2021 · 3 comments
Closed

exec() ignores scope. #87614

Keepun mannequin opened this issue Mar 9, 2021 · 3 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@Keepun
Copy link
Mannequin

Keepun mannequin commented Mar 9, 2021

BPO 43448
Nosy @mdickinson, @eryksun, @Keepun
Superseder
  • bpo-24800: exec docs should note that the no argument form in a local scope is really the two argument form
  • 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 2021-03-10.11:09:55.188>
    created_at = <Date 2021-03-09.15:42:58.560>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7']
    title = 'exec() ignores scope.'
    updated_at = <Date 2021-03-10.11:09:55.187>
    user = 'https://github.com/Keepun'

    bugs.python.org fields:

    activity = <Date 2021-03-10.11:09:55.187>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-10.11:09:55.188>
    closer = 'mark.dickinson'
    components = ['Interpreter Core']
    creation = <Date 2021-03-09.15:42:58.560>
    creator = 'Keepun'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43448
    keywords = []
    message_count = 3.0
    messages = ['388366', '388370', '388425']
    nosy_count = 3.0
    nosy_names = ['mark.dickinson', 'eryksun', 'Keepun']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '24800'
    type = 'behavior'
    url = 'https://bugs.python.org/issue43448'
    versions = ['Python 3.7', 'Python 3.8']

    @Keepun
    Copy link
    Mannequin Author

    Keepun mannequin commented Mar 9, 2021

    exec() ignores scope.

    Code:
    --------------------------

    class ExecTest:
        def public(self):
            h=None
            exec("h='It is public'")
            print(h)
            self._private()
        def _private(self):
            h=None
            exec("h='It is private'", globals(), locals())
            print(h)
    
    h = None
    exec("h='It is global'")
    print(h)
    
    e=ExecTest()
    e.public()

    Result
    --------------------------
    It is global
    None
    None

    --------------------------
    Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)]
    and
    Python 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]

    @Keepun Keepun mannequin added 3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 9, 2021
    @eryksun
    Copy link
    Contributor

    eryksun commented Mar 9, 2021

    exec(obj, globals(), locals()) is the same as exec(obj). Also, locals in a function scope are optimized, so the locals() dict is a snapshot. Modifying the snapshot dict doesn't modify the optimized local variables. At most I think this issue is a duplicate of bpo-24800, to clarify the implicit local scope and behavior.

    @mdickinson
    Copy link
    Member

    At most I think this issue is a duplicate of bpo-24800

    Agreed; closing here.

    @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
    3.7 (EOL) end of life 3.8 only security fixes 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

    2 participants