Dom Grigonis writes:

 > Simply eval/exec string inputs. I sometimes use of these for ad-hoc
 > callbacks. Would be great if `v` was recognised as a code.

Looking at the example, do you mean '=' here?  That is, you want to
add semantics for prefixed '=', meaning "just insert the expression
string here"?

 > Code is similar to this: class A:
 >     def __init__(self):
 >         self.d = {'a': 1, 'b': 2}
 > 
 >     def apply(self, smtp):
 >         for k, v in self.d.items():
 >             if callable(smtp):
 >                 self.d[k] = smtp(v)
 >             elif isinstance(smtp, str):
 >                 self.d[k] = eval(f'{=v}{smtp}')

Since f'{=v}' just results in 'v', why isn't

    self.d[k] = eval(f'v{smtp}')

fine?  Sure, you get the compiler check/refactoring benefit, but as
you admit, this is a very "ad hack" use case.  I don't think we should
encourage it in production code.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PEVTGJOPRWP5SLBLK4UZHISD3EGTRR7K/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to