[Python-Dev] PEP 550 v3 naming (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Thu Aug 24 07:37:19 EDT 2017


On 24 August 2017 at 08:47, Ethan Furman <ethan at stoneleaf.us> wrote:

ContextVars is actually a different name for LogicalContext. So it would be: ExecutionContext = [ContextVars()[, ContextVars()[ ...]]] and you get the (thread.local similar) ContextVars by contextvars = sys.getcontextvars() # or whatever contextvars.verbose = ...

Migrating a (variant of a) naming subthread from python-ideas over to here, does the following sound plausible to anyone else?:

ContextLocal - read/write access API (via get()/set() methods)
ContextLocalNamespace - active mapping that CL.get()/set() manipulates
ExecutionContext - current stack of context local namespaces

Building a threading.local() style helper API would then look something like:

class ContextLocals:
    def __init__(self, key_prefix):
        self._key_prefix = key_prefix

    def __getattr__(self, attr):
        debugging_name = "{}.{}".format(self._key_prefix, attr)
        self.__dict__[attr] = new_local =

sys.new_context_local(debugging_name) return new_local

    def __setattr__(self, attr, value):
        getattr(self, attr).set(value)

    def __delattr__(self, attr):
        getattr(self, attr).set(None)

my_state = ContextLocals(__name__)

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list