[Python-ideas] A "within" keyword

Steven D'Aprano steve at pearwood.info
Sat Jun 9 05:19:50 EDT 2018

On Sat, Jun 09, 2018 at 03:07:39PM +1000, Nick Coghlan wrote:

> It's doable without code generation hacks by using class statements instead
> of with statements.
> The withdrawn PEP 422 shows how to use a custom metaclass to support a
> "namespace" keyword argument in the class header that redirects all writes
> in the body to the given dict:
> https://www.python.org/dev/peps/pep-0422/#new-ways-of-using-classes
> https://www.python.org/dev/peps/pep-0422/#extending-a-class even shows how
> to further use that to extend existing classes with new attributes.

That's awesome! I've been poking away at similar ideas for a long time.


More information about the Python-ideas mailing list