From 251f9d7d5ae22f330686aba4894c6f1e2dbdf60b Mon Sep 17 00:00:00 2001 From: Bob White Date: Thu, 7 Sep 2017 09:35:33 -0500 Subject: [PATCH 1/3] Fix for list.sort requiring keywords in python3.5 Python3.5 changed the parameters in list.sort to be keyword only arguments. This fixes all the instances I could find. --- wx/lib/agw/ribbon/bar.py | 2 +- wx/lib/agw/ultimatelistctrl.py | 2 +- wx/lib/docview.py | 4 ++-- wx/py/shell.py | 2 +- wx/py/sliceshell.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wx/lib/agw/ribbon/bar.py b/wx/lib/agw/ribbon/bar.py index 1a77751c..0a26a14b 100644 --- a/wx/lib/agw/ribbon/bar.py +++ b/wx/lib/agw/ribbon/bar.py @@ -766,7 +766,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=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..20c795ce 100644 --- a/wx/lib/agw/ultimatelistctrl.py +++ b/wx/lib/agw/ultimatelistctrl.py @@ -10406,7 +10406,7 @@ class UltimateListMainWindow(wx.ScrolledWindow): else: self.__func = func - self._lines.sort(self.OnCompareItems) + self._lines.sort(key=self.OnCompareItems) if self.IsShownOnScreen(): self._dirty = True diff --git a/wx/lib/docview.py b/wx/lib/docview.py index 2a48dca4..f5c3af30 100644 --- a/wx/lib/docview.py +++ b/wx/lib/docview.py @@ -2219,7 +2219,7 @@ class DocManager(wx.EvtHandler): if sort: def tempcmp(a, b): return cmp(a.GetDescription(), b.GetDescription()) - templates.sort(tempcmp) + templates.sort(key=tempcmp) strings = [] for temp in templates: @@ -2259,7 +2259,7 @@ class DocManager(wx.EvtHandler): if sort: def tempcmp(a, b): return cmp(a.GetViewTypeName(), b.GetViewTypeName()) - templates.sort(tempcmp) + templates.sort(key=tempcmp) res = wx.GetSingleChoiceIndex(_("Select a document view:"), _("Views"), diff --git a/wx/py/shell.py b/wx/py/shell.py index a5fa6a71..4f68206c 100644 --- a/wx/py/shell.py +++ b/wx/py/shell.py @@ -755,7 +755,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=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..0c811c2f 100644 --- a/wx/py/sliceshell.py +++ b/wx/py/sliceshell.py @@ -2140,7 +2140,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=lambda a, b: cmp(a.lower(), b.lower())) #this is more convenient, isn't it? self.AutoCompSetIgnoreCase(True) From 7b41a3e58f84a1f0ad3b106e42be5e781e831174 Mon Sep 17 00:00:00 2001 From: Bob White Date: Thu, 7 Sep 2017 12:15:38 -0500 Subject: [PATCH 2/3] Using functools.cmp_to_key for old style sorts. --- wx/lib/agw/ribbon/bar.py | 3 ++- wx/lib/agw/ultimatelistctrl.py | 3 ++- wx/lib/docview.py | 5 +++-- wx/py/shell.py | 3 ++- wx/py/sliceshell.py | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/wx/lib/agw/ribbon/bar.py b/wx/lib/agw/ribbon/bar.py index 0a26a14b..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(key=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 20c795ce..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(key=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 f5c3af30..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(key=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(key=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 4f68206c..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(key=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 0c811c2f..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(key=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) From a7f15b3e8091343b6af2ad239a433aa618344d75 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 7 Sep 2017 20:44:05 -0700 Subject: [PATCH 3/3] Add changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) 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)