Re: [Fuego] [PATCH 7/8] Fix TypeError: sort() takes no positional arguments in python3
"Bird, Tim" <[email protected]> Fri, 13 May 2022 22:40:02 +0000
| Newsgroups | dev.linux.lists.fuego |
|---|---|
| Message-ID | <BYAPR13MB250348243C4C3FAA6D6EE7CDFDCA9@BYAPR13MB2503.namprd13.prod.outlook.com> |
> -----Original Message----- > From: [email protected] <[email protected]= m> >=20 > From: sireesha <[email protected]> >=20 > Transform an old-style comparison function to a key function. > use functools.cmp_to_key(func) with sort() function to fix the issue. > This change is compatible with python2 and python3. >=20 > Signed-off-by: sireesha <[email protected]> > Signed-off-by: Shivanand Kunijadar <[email protected]> > --- > scripts/parser/common.py | 5 +++-- > scripts/parser/prepare_chart_data.py | 6 +++--- > 2 files changed, 6 insertions(+), 5 deletions(-) >=20 > diff --git a/scripts/parser/common.py b/scripts/parser/common.py > index a04047a..8c307f1 100644 > --- a/scripts/parser/common.py > +++ b/scripts/parser/common.py > @@ -26,7 +26,8 @@ common.py - This library contains parsing functions > By Daniel Sangorrin (July 2017) > """ >=20 > -import sys, os, re, json, time, collections > +import sys, os, re, json, time, collections, functools > + > from fuego_parser_utils import hls, split_test_id, get_test_case >=20 > loglevel =3D "info" > @@ -562,7 +563,7 @@ def dump_ordered_data(data, indent=3D""): > if type(data)=3D=3Dtype([]): > print("%s[" % indent) > item_list =3D data[:] > - item_list.sort(name_compare) > + item_list.sort(key=3Dfunctools.cmp_to_key(name_compare)) > for item in item_list: > dump_ordered_data(item,indent+" ") > print("%s]" % indent) > diff --git a/scripts/parser/prepare_chart_data.py b/scripts/parser/prepar= e_chart_data.py > index 9aea666..d85315e 100644 > --- a/scripts/parser/prepare_chart_data.py > +++ b/scripts/parser/prepare_chart_data.py > @@ -32,7 +32,7 @@ the results of tests in the Jenkins interface. > By Tim Bird (September 2017) > """ >=20 > -import sys, os, re, json, collections > +import sys, os, re, json, collections, functools > from filelock import FileLock > from operator import itemgetter > from fuego_parser_utils import split_test_id, get_test_case > @@ -507,7 +507,7 @@ def make_measure_tables(test_name, chart_config, entr= ies): >=20 > # one row per test case > tg_list =3D result_map.keys() > - tg_list.sort(cmp_alpha_num) > + tg_list.sort(key=3Dfunctools.cmp_to_key(cmp_alpha_num)) >=20 > for tg in tg_list: > # break apart tguid(tc) and divide into test set and test ca= se > @@ -730,7 +730,7 @@ def make_testcase_table(test_name, chart_config, entr= ies): >=20 > # one row per test case > tc_list =3D result_map.keys() > - tc_list.sort(cmp_alpha_num) > + tc_list.sort(key=3Dfunctools.cmp_to_key(cmp_alpha_num)) >=20 > for tc in tc_list: > row =3D '<tr><td>' + tc + '</td>' > -- > 2.20.1 >=20 Looks good. I don't particularly like that the Python3 language designers = dropped support for cmp functions. If you look under the hood, this 'key function' nonsens= e just implements a cmp under several more layers of abstraction. It's inexcusable to break = backwards=20 compatibility like this (removing sort()'s positional arguments), especiall= y when it creates worthless abstraction layers as a requirement for forward-porting. However, none of that is your fault. Thanks for the patch. Sorry for the = rant. Sigh - have I told anyone lately how much I dislike Python3 and their langu= age development policies? -- Tim