Objects/stringobject/strformat

Source   Edit  

for PyObject being working with std/strformat

Types

FormatPyObjectError = object of CatchableError
inner Source   Edit  

Procs

proc formatValue[O: PyObject](s: var string; obj: O; specS: static[string]) {.
    ...raises: [FormatPyObjectError].}
remember to wrap around handleFormatExc Source   Edit  
proc formatValue[O: PyObject](s: var string; obj: O; specS: string) {.
    ...raises: [FormatPyObjectError].}
remember to wrap around handleFormatExc Source   Edit  

Templates

template `&`(fun; str: string{lit}): PyObject

PyUnicode_FromFormat <- newPyStr&"xxx {v:spec} xxx"

XXX: we use & to cheat LSP to work (for syntax highlight)

Example:

let a = newPyAscii"e"
discard newPyStr&"abc {a}"
Source   Edit  
template handleFormatExc(body)
Source   Edit  
template handleFormatExc(handle, body)
Source   Edit