Re: [PATCH v8 06/11] iotests: drop Python 3.4 compatibility code
On 3/24/20 10:54 AM, Max Reitz wrote: > On 17.03.20 01:41, John Snow wrote: >> We no longer need to accommodate 3.4, drop this code. > > Pre-3.4, actually. > >> (Also, the line is over 79 characters, so drop it.) >> >> Touch up the docstring a little bit while we're here. >> >> Signed-off-by: John Snow >> --- >> tests/qemu-iotests/iotests.py | 14 +++--- >> 1 file changed, 7 insertions(+), 7 deletions(-) >> >> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py >> index 7cd74e7cb1..3d90fb157d 100644 >> --- a/tests/qemu-iotests/iotests.py >> +++ b/tests/qemu-iotests/iotests.py >> @@ -22,6 +22,7 @@ >> import unittest >> import sys >> import struct >> +from typing import Optional >> import json >> import signal >> import logging >> @@ -350,18 +351,17 @@ def _filter(_key, value): >> return value >> return filter_qmp(qmsg, _filter) >> >> -def log(msg, filters=(), indent=None): >> -'''Logs either a string message or a JSON serializable message (like >> QMP). >> -If indent is provided, JSON serializable messages are pretty-printed.''' >> +def log(msg, filters=(), indent: Optional[int] = None) -> None: >> +""" >> +Logs either a string message or a JSON serializable message (like QMP). >> +If indent is provided, JSON serializable messages are pretty-printed. >> +""" > > I feel like I should complain about this unrelated (I think?) change, > but I won’t. > It just seemed like so little to have in its own little patch, and I wasn't prepared to fix the docstrings in the whole file ... ... It will be a future patch that tidies up this whole file and drops the missing-docstring ignore from pylintrc. > Reviewed-by: Max Reitz > Thanks. >> for flt in filters: >> msg = flt(msg) >> if isinstance(msg, (dict, list)): >> -# Python < 3.4 needs to know not to add whitespace when >> pretty-printing: >> -separators = (', ', ': ') if indent is None else (',', ': ') >> # Don't sort if it's already sorted >> do_sort = not isinstance(msg, OrderedDict) >> -print(json.dumps(msg, sort_keys=do_sort, >> - indent=indent, separators=separators)) >> +print(json.dumps(msg, sort_keys=do_sort, indent=indent)) >> else: >> print(msg) >> >> > >
Re: [PATCH v8 06/11] iotests: drop Python 3.4 compatibility code
On 17.03.20 01:41, John Snow wrote: > We no longer need to accommodate 3.4, drop this code. Pre-3.4, actually. > (Also, the line is over 79 characters, so drop it.) > > Touch up the docstring a little bit while we're here. > > Signed-off-by: John Snow > --- > tests/qemu-iotests/iotests.py | 14 +++--- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py > index 7cd74e7cb1..3d90fb157d 100644 > --- a/tests/qemu-iotests/iotests.py > +++ b/tests/qemu-iotests/iotests.py > @@ -22,6 +22,7 @@ > import unittest > import sys > import struct > +from typing import Optional > import json > import signal > import logging > @@ -350,18 +351,17 @@ def _filter(_key, value): > return value > return filter_qmp(qmsg, _filter) > > -def log(msg, filters=(), indent=None): > -'''Logs either a string message or a JSON serializable message (like > QMP). > -If indent is provided, JSON serializable messages are pretty-printed.''' > +def log(msg, filters=(), indent: Optional[int] = None) -> None: > +""" > +Logs either a string message or a JSON serializable message (like QMP). > +If indent is provided, JSON serializable messages are pretty-printed. > +""" I feel like I should complain about this unrelated (I think?) change, but I won’t. Reviewed-by: Max Reitz > for flt in filters: > msg = flt(msg) > if isinstance(msg, (dict, list)): > -# Python < 3.4 needs to know not to add whitespace when > pretty-printing: > -separators = (', ', ': ') if indent is None else (',', ': ') > # Don't sort if it's already sorted > do_sort = not isinstance(msg, OrderedDict) > -print(json.dumps(msg, sort_keys=do_sort, > - indent=indent, separators=separators)) > +print(json.dumps(msg, sort_keys=do_sort, indent=indent)) > else: > print(msg) > > signature.asc Description: OpenPGP digital signature
[PATCH v8 06/11] iotests: drop Python 3.4 compatibility code
We no longer need to accommodate 3.4, drop this code. (Also, the line is over 79 characters, so drop it.) Touch up the docstring a little bit while we're here. Signed-off-by: John Snow --- tests/qemu-iotests/iotests.py | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 7cd74e7cb1..3d90fb157d 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -22,6 +22,7 @@ import unittest import sys import struct +from typing import Optional import json import signal import logging @@ -350,18 +351,17 @@ def _filter(_key, value): return value return filter_qmp(qmsg, _filter) -def log(msg, filters=(), indent=None): -'''Logs either a string message or a JSON serializable message (like QMP). -If indent is provided, JSON serializable messages are pretty-printed.''' +def log(msg, filters=(), indent: Optional[int] = None) -> None: +""" +Logs either a string message or a JSON serializable message (like QMP). +If indent is provided, JSON serializable messages are pretty-printed. +""" for flt in filters: msg = flt(msg) if isinstance(msg, (dict, list)): -# Python < 3.4 needs to know not to add whitespace when pretty-printing: -separators = (', ', ': ') if indent is None else (',', ': ') # Don't sort if it's already sorted do_sort = not isinstance(msg, OrderedDict) -print(json.dumps(msg, sort_keys=do_sort, - indent=indent, separators=separators)) +print(json.dumps(msg, sort_keys=do_sort, indent=indent)) else: print(msg) -- 2.21.1