From 029f337cc743f12dff9278823f0529b8d026fff7 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 14 Nov 2019 11:01:49 -0500 Subject: [PATCH] Fix sorting so it can't use a dictionary in the comparison. Fixes #394. --- sources/openslide/large_image_source_openslide/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sources/openslide/large_image_source_openslide/__init__.py b/sources/openslide/large_image_source_openslide/__init__.py index c580f84ca..13a2d51f9 100644 --- a/sources/openslide/large_image_source_openslide/__init__.py +++ b/sources/openslide/large_image_source_openslide/__init__.py @@ -202,12 +202,13 @@ def _getAvailableLevels(self, path): 'height': svsLevelDimensions[svslevel][1], } if level['width'] > 0 and level['height'] > 0: - # add to the list so that we can sort by resolution - levels.append((level['width'] * level['height'], level)) + # add to the list so that we can sort by resolution and + # then by earlier entries + levels.append((level['width'] * level['height'], -len(levels), level)) except openslide.lowlevel.OpenSlideError: self._openslide = openslide.OpenSlide(path) # sort highest resolution first. - levels = [entry[-1] for entry in sorted(levels, reverse=True)] + levels = [entry[-1] for entry in sorted(levels, reverse=True, key=lambda x: x[:-1])] # Discard levels that are not a power-of-two compared to the highest # resolution level. levels = [entry for entry in levels if