On Wed, Mar 15, 2023 at 8:13 AM Philippe Mathieu-Daudé <phi...@linaro.org> wrote: > > On 15/3/23 12:16, Daniel P. Berrangé wrote: > > On Wed, Mar 15, 2023 at 08:43:33AM +0100, Philippe Mathieu-Daudé wrote: > >> Hi Marco, > >> > >> (+Python experts) > >> > >> On 13/3/23 18:25, Marco Liebel wrote: > >>> Replace python 2 format string with f-strings > >>> > >>> Signed-off-by: Marco Liebel <quic_mlie...@quicinc.com> > >>> --- > >>> target/hexagon/gen_helper_funcs.py | 54 ++-- > >>> target/hexagon/gen_helper_protos.py | 10 +- > >>> target/hexagon/gen_idef_parser_funcs.py | 8 +- > >>> target/hexagon/gen_op_attribs.py | 4 +- > >>> target/hexagon/gen_op_regs.py | 10 +- > >>> target/hexagon/gen_opcodes_def.py | 2 +- > >>> target/hexagon/gen_printinsn.py | 14 +- > >>> target/hexagon/gen_shortcode.py | 2 +- > >>> target/hexagon/gen_tcg_func_table.py | 2 +- > >>> target/hexagon/gen_tcg_funcs.py | 317 +++++++++++------------- > >>> target/hexagon/hex_common.py | 4 +- > >>> 11 files changed, 198 insertions(+), 229 deletions(-) > >> > >> These files use a mix of ', " and '''... Since you are modifying > >> them, it would be nice to unify. I'm not sure there is a recommended > >> style; matter of taste, I find the single quote (') less aggressive, > >> then escaping it using ", and keeping ''' for multi-lines strings. > >
I pretty much agree with Dan, it's best to use a formatting tool and just stick with it. We don't have a unified standard across the code base right now, and it would be rude to make that a pre-requisite of a patch like this. Until then, docstrings should use triple-double quotes. Any other string can use whatever quoting style happens to be most convenient for the string being written to minimize escaping. Consistency is nice where reasonable, but minimizing escapes by using different styles on an as-needed basis is a respectable and good thing. I glanced *very quickly* at these files and it looks like the style is to use double quotes for format strings and single quotes for constant strings. That seems fine to me. > > FWIW, rather than debating code style issues and coming up with a custom > > set of rules for QEMU python code, my recommendation would be to consider > > adopting 'black' > > > > https://black.readthedocs.io/en/stable/ > > > > There is a trend with recent languages to offer an opinionated code > > formatting tool as standard to maximise consistency across projects > > in a given language. 'black' is a decent attempt to bring this to > > the python world. I found it pretty liberating when doing recent > > python work in libvirt, to be able to mostly not worry about formatting > > anymore. > > Clever. > > So per 'black -t py37' the style is """, I was not even close. > > > The main downside is the bulk-reformat in the history, which can > > make backports more challenging. For "git blame" you can use the > > .git-blame-ignore-revs file to hide the reformats. > > TIL .git-blame-ignore-revs, thanks! > Huh, that's awesome.