On Mon, Jul 29, 2019 at 09:53:38PM -0400, Ricky Teachey wrote:
> But I ask: how is it possible, then, to create a with block that "gobbles
> up" things declared in it and adds those things to some namespace using
> existing python syntax...?
[...]
> I currently can't create an object that allows this to work:
>
> with NameSpace('ns') as ns:
> a = 1
> assert ns.a=1
Neither can I, and I've been mucking about with this idea for about
three years. (To be honest, I poke it with a stick about every six
months, so its not like I've spend a lot of time on it.)
I kinda-sorta got it to work with a class statement plus a decorator,
not too different from your metaclass example, but couldn't get
functions to work correctly.
But if I understand the original post here:
https://mail.python.org/archives/list/[email protected]/message/TAVHEKDZVYKJUGZKWSVZVAOGBPLZVKQG/
Batuhan Taskaya has got it to work using a dict. If that's the case,
that seems to be the hardest part done.
(On the other hand, if this is just a hypothetical "wouldn't it be cool
if this worked?" post, then we're actually no closer to a technical
solution.)
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/M55BXCBOPRCQW6MXX6TVVIAKRDOJJEGF/
Code of Conduct: http://python.org/psf/codeofconduct/