{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Globals namespace for an embedded shell."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Code typed in an embedded shell is compiled as module-level code, so any new nested scope it creates (a lambda, a generator expression, a comprehension, a function body...) looks its free variables up in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "globals()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", not in the local namespace the shell was embedded in. With a plain module "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__dict__"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " as globals this makes the caller's local variables invisible to those scopes (gh-136)      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "def f():\n    x = 1\n    embed()   # then type: (lambda: x)()  -> NameError",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This dict subclass keeps the interpreter's normal, C-level storage as a snapshot of the caller module's globals, but resolves reads through the caller's local namespace first, mimicking the closure lookup the code would have had if it were written in place. The interpreter only honors this "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__getitem__"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " override because the shell passes a dict "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "subclass"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "exec"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which disables the exact-dict fast path of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "LOAD_GLOBAL"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "STORE_GLOBAL"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "/"
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "DELETE_GLOBAL"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " bypass "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "__setitem__"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " overrides and mutate the C-level storage directly, so "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "sync_to_module",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "IPython.terminal.embed:_EmbedGlobals.sync_to_module"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " propagates those (rare) mutations back to the real module on exit."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Returns",
    "Yields",
    "Receives",
    "Raises",
    "Warns",
    "Other Parameters",
    "Attributes",
    "Methods",
    "Notes",
    "Warnings"
  ],
  "item_file": "/dev/ipython/IPython/terminal/embed.py",
  "item_line": 22,
  "item_type": "class",
  "aliases": [
    "IPython.terminal.embed._EmbedGlobals"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "module_dict",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "local_ns",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "_EmbedGlobals"
  },
  "references": null,
  "qa": "IPython.terminal.embed:_EmbedGlobals",
  "arbitrary": [],
  "local_refs": []
}