Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9dfb35d

Browse files
committed
Make backend_pdf.Name comparable and hashable
1 parent e76e607 commit 9dfb35d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import warnings
1919
import zlib
2020
from io import BytesIO
21+
from functools import total_ordering
2122

2223
import numpy as np
2324
from matplotlib.externals.six import unichr
@@ -183,7 +184,7 @@ def pdfRepr(obj):
183184
elif isinstance(obj, dict):
184185
r = [b"<<"]
185186
r.extend([Name(key).pdfRepr() + b" " + pdfRepr(obj[key])
186-
for key in sorted(six.iterkeys(obj))])
187+
for key in sorted(obj)])
187188
r.append(b">>")
188189
return fill(r)
189190

@@ -243,6 +244,7 @@ def write(self, contents, file):
243244
write(b"\nendobj\n")
244245

245246

247+
@total_ordering
246248
class Name(object):
247249
"""PDF name object."""
248250
__slots__ = ('name',)
@@ -262,6 +264,15 @@ def __repr__(self):
262264
def __str__(self):
263265
return '/' + six.text_type(self.name)
264266

267+
def __eq__(self, other):
268+
return isinstance(other, Name) and self.name == other.name
269+
270+
def __lt__(self, other):
271+
return isinstance(other, Name) and self.name < other.name
272+
273+
def __hash__(self):
274+
return hash(self.name)
275+
265276
@staticmethod
266277
def hexify(match):
267278
return '#%02x' % ord(match.group())

0 commit comments

Comments
 (0)