[Python-ideas] User-defined literals

Terry Reedy tjreedy at udel.edu
Wed Jun 3 02:05:42 CEST 2015

On 6/2/2015 3:40 PM, Chris Angelico wrote:
> On Wed, Jun 3, 2015 at 5:03 AM, Andrew Barnert via Python-ideas

>> Similarly, this idea could be extended to handle all literal types, so you can do `{'spam': 1, 'eggs': 2}_o` to create an OrderedDict literal, but I think that's ugly enough to not be worth proposing. (A prefix looks better there... but a prefix doesn't work for numbers or strings. And I'm not sure it's unambiguously parseable even for list/set/dict.) Plus, there's the problem that comprehensions and actual literals are both parsed as displays, but you wouldn't want user-defined comprehensions.
> I thought there was no such thing as a dict/list/set literal, only
> display syntax?

Correct.  Only number and string literals. Displays are atomic runtime 
expressions.  'expression_list' and 'comprehension' are alternate 
contents of a display. 6.2.4. Displays for lists, sets and dictionaries
Terry Jan Reedy

More information about the Python-ideas mailing list