python: Switch from using compare to key in list sort
authorAndreas Sandberg <andreas.sandberg@arm.com>
Sat, 26 Jan 2019 09:55:35 +0000 (09:55 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Wed, 13 Feb 2019 09:52:37 +0000 (09:52 +0000)
Python 3 has deprecated the use of a comparison function in favour of
a key extraction function.

Change-Id: I4b7eab791ecbdfbf7147f57fdbc7cbe8f1de20dd
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/15995
Reviewed-by: Gabe Black <gabeblack@google.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
src/python/m5/stats/__init__.py

index ba91f22c7d813ee946786361668b0fc076bb9e9f..acb62f13e4e0941b98822fa60314a491ad5cf9dd 100644 (file)
@@ -169,12 +169,7 @@ def enable():
         if not (stat.flags & flags.display):
             stat.name = "__Stat%06d" % stat.id
 
-    def less(stat1, stat2):
-        v1 = stat1.name.split('.')
-        v2 = stat2.name.split('.')
-        return v1 < v2
-
-    stats_list.sort(less)
+    stats_list.sort(key=lambda s: s.name.split('.'))
     for stat in stats_list:
         stats_dict[stat.name] = stat
         stat.enable()