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

Nick Coghlan ncoghlan at gmail.com
Sat Aug 19 04:17:31 EDT 2017


On 19 August 2017 at 06:33, Yury Selivanov <yselivanov.ml at gmail.com> wrote:

Hi,

This is a third iteration of the PEP. There was some really good feedback on python-ideas and the discussion thread became hard to follow again, so I decided to update the PEP only three days after I published the previous version. Summary of the changes can be found in the "Version History" section: https://www.python.org/dev/peps/pep-0550/#version-history There are a few open questions left, namely the terminology and design of ContextKey API. On the former topic, I'm quite happy with the latest version: Execution Context, Logical Context, and Context Key.

Nice, I quite like this version of the naming scheme and the core design in general.

While Guido has a point using the same noun for two different things being somewhat confusing, I think the parallel here is the one between the local scope and the lexical (nonlocal) scope for variable names - just as your lexical scope is a nested stack of local scopes in outer functions, your execution context is your current logical context plus a nested stack of outer logical contexts.

Generator Object Modifications ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To achieve this, we make a small set of modifications to the generator object: * New _logicalcontext_ attribute. This attribute is readable and writable for Python code. * When a generator object is instantiated its _logicalcontext_ is initialized with an empty LogicalContext. * Generator's .send() and .throw() methods are modified as follows (in pseudo-C):: if gen.logicalcontext is not NULL: tstate = PyThreadStateGet() tstate.executioncontext.push(gen.logicalcontext) try: # Perform the actual Generator.send() or # Generator.throw() call. return gen.send(...) finally: gen.logicalcontext = tstate.executioncontext.pop() else: # Perform the actual Generator.send() or # Generator.throw() call. return gen.send(...)

I think this pseudo-code expansion includes a few holdovers from the original visibly-immutable API design.

Given the changes since then, I think this would be clearer if the first branch used sys.run_with_logical_context(), since the logical context references at the Python layer now behave like shared mutable objects, and the apparent immutability of sys.run_with_execution_context() comes from injecting a fresh logical context every time.

Also +1 to the new design considerations questions that explicitly postpones consideration of any of my "What about..."" questions from python-ideas to future PEPs.

Cheers, Nick.

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



More information about the Python-Dev mailing list