
On Sun, Apr 19, 2020 at 11:40 PM Steven D'Aprano <steve@pearwood.info> wrote: def M(*vals): # ... magic stuff ... return dct
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
Yep. It works in IPython and it works in a script, but I didn't try the plain Python shell. I'm using Python 3.8, but I imagine the same problem exists between IPython and Python shell in other versions. etc, and how many hours of debugging it will take to get it to work.
Some positive but finite number of hours to deal with the edge cases. For the discussion, can we just stipulate some future L() that is a better version of M()? (base) 551-bin % python auto-dict.py {'alpha': 'something'} args: () kws: {'alpha': 'something', 'beta': 'else', 'gamma': 'again'} (base) 552-bin % cat auto-dict.py from magic import M alpha = 'something' beta = 'else' gamma = 'again' print(M(alpha)) def show(*args, **kws): print('args:', args) print('kws:', kws) show(**M(alpha, beta, gamma))
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.
Yes... in L() is should be `ast.literal_eval()`. Maybe I'll write a better L() in the next day or two. But I really AM NOT pushing for anyone to use such a thing, just to consider the conceptual space it occupies vs. having new syntax. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.