[Python-ideas] frozenset literals

Guido van Rossum guido at python.org
Sat Feb 2 20:25:46 CET 2013


On Sat, Feb 2, 2013 at 11:07 AM, MRAB <python at mrabarnett.plus.com> wrote:
> On 2013-02-02 18:46, Hua Lu wrote:
>>
>> On Sat, Feb 2, 2013 at 12:30 PM, MRAB <python at mrabarnett.plus.com> wrote:
>>>
>>> On 2013-02-02 14:28, Antoine Pitrou wrote:
>>>>
>>>> On Sun, 03 Feb 2013 01:20:38 +1100
>>>> Steven D'Aprano <steve at pearwood.info> wrote:
>>>>>
>>>>>
>>>>> Unfortunately the proposal to use f{ ... } for frozen sets cannot work
>>>>> within the constraints of Python's lexer:
>>>>>
>>>>> http://mail.python.org/pipermail/python-3000/2008-January/011838.html
>>>>>
>>>>> Unfortunately we're running out of useful, easy to enter symbols for
>>>>> literals. Until such time (Python4000 perhaps, or more likely
>>>>> Python5000) as
>>>>> we can use a rich set of Unicode literals, I don't think there is any
>>>>> clear
>>>>> way to have a frozenset literal.
>>>>
>>>>
>>>> I'm not sure what the point is. frozensets are too rarely used to
>>>> deserve a literal notation.
>>>>
>>> Does it need a special notation as such?
>>>
>>> Wouldn't an alternative be to support "frozenset(...)" where "..." is
>>> parseable by ast.literal_eval()?
>>>
>>> The same thing could be done with some other built-in classes.
>>>
>> Perhaps, but we'd have to be careful with how we introduce those symbols:
>>
>> http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
>>
>> You could possibly not allow attribute access but permit those
>> symbols... is there an exploit possible with that much filtering?
>>
> I'm talking about hard-coding "frozenset(...)" and a few other built-in
> classes to return the appropriate object, so, for example, "set([0, 1,
> 2])" would be the same as "{0, 1, 2}".

You're proposing to do this just for literal_eval(), right? But how
would you implement it? It seems it would require lots of special
cases. Where would you stop? dict(key1=..., key2=...)? list({...})?

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list