[Python-ideas] frozenset literals

Chris Angelico rosuav at gmail.com
Sun Feb 3 03:22:03 CET 2013


On Sun, Feb 3, 2013 at 1:18 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> I think that having literal_eval support non-literals is a bad, bad idea.
> Let's just not go there. It will surely end in tears.
>
> However, I think that having something in between the strictness of
> literal_eval and the dangerous "anything goes" power of eval is a good idea.
> For a long time now I've toyed with an engine for building expression
> evaluators. Something that understands operators, function calls, etc, and
> you can tell it what names to accept. My main motivation is for evaluating
> mathematical expressions like:
>
> 5x^3 - 2x + log(1/y) + n!/√π

This sounds like a good idea, especially if there can be some way to
enforce that these names may ONLY be called - you can't piggyback on
log to get other functionality with log.__globals__ etc. That would
cover frozenset quite happily.

ChrisA



More information about the Python-ideas mailing list