rose
rose copied to clipboard
Replacement for python2 `cmp` functions
During the conversion from python2 to 3 @wxtim has used:
-cmp(a, b)
+(a>b) - (a<b)
in
- lib/python/rose/config.py
- lib/python/rose/macro.py
- lib/python/rose/namelist_dump.py
- lib/python/rose/suite_clean.py
This is subtracting booleans, which is ugly and non-intuitive.
Additionally this logic is used in functions called thus:
-list_.sort(sort_function)
+from functools import cmp_to_key
+list_sort(key=cmp_to_key(sort_func)
This logic should be tidied up, preferably deprecating the use of cmp_to_key.
Proposed work:
- Use Pytest to create functional tests at the level of calling
list_.sort(key=cmp_to_key(sort_func)) - Change the sort functions to key functions, if possible.
During the conversion from python2 to 3 @wxtim has used...
Oh that @wxtim! :smile: