X Tutup
The Wayback Machine - https://web.archive.org/web/20250616111635/https://github.com/python/cpython/issues/92681
Skip to content

locals are not passed to inner function defined in exec() #92681

Closed as not planned
@sinoleao-1

Description

@sinoleao-1

Bug report

A clear and concise description of what the bug is.
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.

With following code, f1 is OK, but f2 failed with the error "name 'a' is not defined"

 def f1():
    a = "hello"
    exec("print(a)")
 
 def f2():
    a = "hello"
    exec("def inner(): print(a)\ninner()")
 
 f1()
 f2()

Your environment

  • CPython versions tested on:
    Python 3.5.2 (default, Aug 10 2017, 23:51:58)
    [GCC 4.4.3] on linux

  • Operating system and architecture:
    Linux 3.10.0-1160.25.1.el7.x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup