[Python-ideas] Possible method of distinguishing between set-literals, dict-literals, and odict-literals

Terry Reedy tjreedy at udel.edu
Tue Jun 16 20:24:06 CEST 2009

Carl Johnson wrote:
> I thought of this in the shower. It might not be a good idea, but I'd
> like to hear what other people think. On analogy with b"", r"", etc.
> we could introduce an empty set-literal and an odict-literal, and add
> a more explicit form to replace the existing set literal. s{} could be
> the empty set, o{} could be an empty odict, and we could leave {}
> alone as the form for dicts. So, an odict literal would look like
> o{'a':'1', 'b':'2', 'c':'3'} instead of OrderedDict([('a', '1'), ('b',
> '2'), ('c', '3')]). And the set {'a', 'c', 'b'} could (optionally?)
> have a little s{'a', 'c', 'b'} to make it more explicit that this is a
> set, not a dict.
> I suppose if we wanted to get crazy, we could also have a frozenset
> literal, fs{}…
> So what do people think? Is this too ugly to do? Does it confuse users
> who are used to C-style braces? Or is it a logical extension of the
> b"", r"", etc. system that could help make things follow EIBI better?

I consider b"" and r"" to be hacks, necessary but not to be imitated 
without such necessity. I believe both affect how the lexer interprets 
code characters when it constructs literal value tokens to be fed to the 

Collection-content displays are not, in general, constant and generally 
produce run-time code.

More information about the Python-ideas mailing list