[Python-Dev] PEP-498: Literal String Formatting

Barry Warsaw barry at python.org
Tue Aug 11 15:44:49 CEST 2015


On Aug 10, 2015, at 11:05 PM, ISAAC J SCHWABACHER wrote:

>code.putlines(f"""
>static char {entry.doc_cname}[] = "{
>    split_string_literal(escape_bytestring(docstr))}";
>
>{ # nested!
>f"""
>#if CYTHON_COMPILING_IN_CPYTHON
>    struct wrapperbase {entry.wrapperbase_cname};
>#endif
>""" if entry.is_special else ''}
>
>{(lambda temp, argn: # my kingdom for a let!
>f"""
>for ({temp}=0; {temp}<PyTuple_GET_SIZE({argn}); {temp}++) {{
>    PyObject *item = PyTuple_GET_ITEM({argn}, {temp});
>}}""")(..., Naming.args_cname)}
>
>{self.starstar_arg.entry.cname} =
>    ({Naming.kwds_cname}) ? PyDict_Copy({Naming.kwds_cname})
>                          : PyDict_New();
>
>if (unlikely(!{self.starstar_arg.entry.cname})) return {self.error_value()};
>""")
>
>What do others think of this PEP-498 sample?

No offense intended, but I put this in an Emacs Python buffer and it made me
want to cry.

Cheers,
-Barry


More information about the Python-Dev mailing list