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

Skip to content

Commit ee60905

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

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 11 additions & 0 deletions
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
@@ -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)