From 14b86be314fd2d4e900729cac16e39060d01a252 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Wed, 22 May 2024 14:56:50 +1000 Subject: [PATCH 1/2] DOCS: fix error in exec namespace note When updating the new exec note added in gh-119235 as part of the PEP 667 general docs PR, I suggested a workaround that isn't valid. Since it's far from the first time I've considered that workaround, and the fact it doesn't work has surprised me every time, amend the new note to explicitly state that dict merging is the only option. --- Doc/library/functions.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index a879ddbca92e82..86cd3123b354ef 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -623,10 +623,10 @@ are always available. They are listed here in alphabetical order. means functions and classes defined in the executed code will not be able to access variables assigned at the top level (as the "top level" variables are treated as class variables in a class definition). - Passing a :class:`collections.ChainMap` instance as *globals* allows name - lookups to be chained across multiple mappings without triggering this - behaviour. Values assigned to top level names in the executed code can be - retrieved by passing an empty dictionary as the first entry in the chain. + As *globals* is required to be a ``dict`` instance, it isn't possible to + use :class:`collections.ChainMap` to work around this restriction. + Instead, any namespaces to be used for lookups must be merged into a + single ``dict`` before calling ``exec``. If the *globals* dictionary does not contain a value for the key ``__builtins__``, a reference to the dictionary of the built-in module From 9b41eab654280675d759f71ce2f531a6fb14b851 Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Wed, 22 May 2024 16:20:58 +1000 Subject: [PATCH 2/2] Just delete the incorrect workaround --- Doc/library/functions.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 86cd3123b354ef..cb9b650badcfbd 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -623,10 +623,6 @@ are always available. They are listed here in alphabetical order. means functions and classes defined in the executed code will not be able to access variables assigned at the top level (as the "top level" variables are treated as class variables in a class definition). - As *globals* is required to be a ``dict`` instance, it isn't possible to - use :class:`collections.ChainMap` to work around this restriction. - Instead, any namespaces to be used for lookups must be merged into a - single ``dict`` before calling ``exec``. If the *globals* dictionary does not contain a value for the key ``__builtins__``, a reference to the dictionary of the built-in module