diff --git a/CHANGES.rst b/CHANGES.rst index 2b0d994e..3617f181 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -75,6 +75,8 @@ Changes in this release include the following: * Fix missing imports needed for drawing the legend in wx.lib.plot. (#503) +* Fix other instances of list.sort using old cmp-style ordering functions. + (#508) diff --git a/wx/lib/agw/ribbon/bar.py b/wx/lib/agw/ribbon/bar.py index 1a77751c..e755fb60 100644 --- a/wx/lib/agw/ribbon/bar.py +++ b/wx/lib/agw/ribbon/bar.py @@ -96,6 +96,7 @@ See Also import wx +from functools import cmp_to_key import six @@ -766,7 +767,7 @@ class RibbonBar(RibbonControl): # Sneaky obj array trickery to not copy the tab descriptors sorted_pages.append(info) - sorted_pages.sort(self.OrderPageTabInfoBySmallWidthAsc) + sorted_pages.sort(key=cmp_to_key(self.OrderPageTabInfoBySmallWidthAsc)) width -= tabsep*(numtabs - 1) for i, info in enumerate(self._pages): diff --git a/wx/lib/agw/ultimatelistctrl.py b/wx/lib/agw/ultimatelistctrl.py index 2af9321a..410d071e 100644 --- a/wx/lib/agw/ultimatelistctrl.py +++ b/wx/lib/agw/ultimatelistctrl.py @@ -236,6 +236,7 @@ import wx import math import bisect import zlib +from functools import cmp_to_key import six @@ -10406,7 +10407,7 @@ class UltimateListMainWindow(wx.ScrolledWindow): else: self.__func = func - self._lines.sort(self.OnCompareItems) + self._lines.sort(key=cmp_to_key(self.OnCompareItems)) if self.IsShownOnScreen(): self._dirty = True diff --git a/wx/lib/docview.py b/wx/lib/docview.py index 2a48dca4..1b4547a7 100644 --- a/wx/lib/docview.py +++ b/wx/lib/docview.py @@ -16,6 +16,7 @@ import os.path import shutil import wx import sys +from functools import cmp_to_key _ = wx.GetTranslation @@ -2219,7 +2220,7 @@ class DocManager(wx.EvtHandler): if sort: def tempcmp(a, b): return cmp(a.GetDescription(), b.GetDescription()) - templates.sort(tempcmp) + templates.sort(key=cmp_to_key(tempcmp)) strings = [] for temp in templates: @@ -2259,7 +2260,7 @@ class DocManager(wx.EvtHandler): if sort: def tempcmp(a, b): return cmp(a.GetViewTypeName(), b.GetViewTypeName()) - templates.sort(tempcmp) + templates.sort(key=cmp_to_key(tempcmp)) res = wx.GetSingleChoiceIndex(_("Select a document view:"), _("Views"), diff --git a/wx/py/shell.py b/wx/py/shell.py index a5fa6a71..e31bff67 100644 --- a/wx/py/shell.py +++ b/wx/py/shell.py @@ -14,6 +14,7 @@ import keyword import os import sys import time +from functools import cmp_to_key from .buffer import Buffer from . import dispatcher @@ -755,7 +756,7 @@ class Shell(editwindow.EditWindow): #sort lowercase def _cmp(a,b): return ((a > b) - (a < b)) - unlist.sort(lambda a, b: _cmp(a.lower(), b.lower())) + unlist.sort(key=cmp_to_key(lambda a, b: _cmp(a.lower(), b.lower()))) #this is more convenient, isn't it? self.AutoCompSetIgnoreCase(True) diff --git a/wx/py/sliceshell.py b/wx/py/sliceshell.py index fe3763fe..9d1361f9 100644 --- a/wx/py/sliceshell.py +++ b/wx/py/sliceshell.py @@ -21,6 +21,7 @@ import keyword import os import sys import time +from functools import cmp_to_key from .buffer import Buffer from . import dispatcher @@ -2140,7 +2141,7 @@ class SlicesShell(editwindow.EditWindow): unlist = [thlist[i] for i in xrange(len(thlist)) if thlist[i] not in thlist[:i]] #sort lowercase - unlist.sort(lambda a, b: cmp(a.lower(), b.lower())) + unlist.sort(key=cmp_to_key(lambda a, b: cmp(a.lower(), b.lower()))) #this is more convenient, isn't it? self.AutoCompSetIgnoreCase(True)