On Sun, Apr 19, 2020 at 04:14:51PM -0400, David Mertz wrote:
> Per your wish, Eric, the glorious successor of Q() ... named M():
>
> >>> def M(*vals):
> ... import sys
> ... import inspect
> ... caller = sys._getframe(1)
> ... call = inspect.stack()[1].code_context[0]
> ... _, call = call.split('M(')
> ... call = call.strip()[:-1]
> ... names = [name.strip() for name in call.split(',')]
> ... dct = {}
> ... for name in names:
> ... dct[name] = eval(name, globals(), caller.f_locals)
> ... return dct
When I try it I get this:
py> alpha = 'something'
py> M(alpha)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in M
TypeError: 'NoneType' object is not subscriptable
Tried and failed in both 3.5 and 3.8, so I'm not sure what version of
Python you are using where it works, or under what conditions.
Your example M(x, y, z) fails with the same error.
Since this is fundamentally broken and doesn't work for me, I can't test
it, but I wonder how well it will cope for things like:
func(arg, FunctionM(x, y), M(z))
M(x, M(y)['y'])
func(arg, M(
x,
y,
),
z)
etc, and how many hours of debugging it will take to get it to work.
I'm also looking at that call to eval and wondering if someone smarter
than me can use that to trick me into evaluating something I don't like.
--
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/NEPHZXR53V3BSH7ZYMXQN5N3VSLMFPMQ/
Code of Conduct: http://python.org/psf/codeofconduct/