[Python-ideas] datetime.timedelta literals

Paul Moore p.f.moore at gmail.com
Mon Jun 4 07:38:03 EDT 2018

On 4 June 2018 at 11:59, Pål Grønås Drange <paal.drange at gmail.com> wrote:
> One thing that could solve both this proposal and the aforementioned
> SI-proposition by Ken Kundert, could be supporting user-defined
> literals.  Suppose that __litXXX___ would make XXX a literal one could
> use as a suffix for numbers and strings (and lists, dicts, sets?).
> A user-defined literal could be defined as __lit<insert literal>__,
> though I don't know how to import it.

The killer would be putting together a full proposal, though. Unless
you mean something very different from the norm when you say
"literal", literals are evaluated very early in the parsing process,
long before user-defined functions are accessible.

If what you actually mean is a specialised function calling syntax
(where NNN_suf is parsed as the a "literal call" of "suf" with the
number NNN as an argument, so it translates to a call to (something
like) __lit_suf__(NNN) at runtime, then that's probably possible, but
it's extremely unclear why that function-call syntax has any
significant advantage over the standard syntax suf(NNN).

"readability" is notoriously difficult to argue, and "allows
construction of domain-specific languages" is pretty much an anti-goal
in Python. So what's left to justify this?


More information about the Python-ideas mailing list