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

Skip to content

Commit 70dc0d1

Browse files
More robust FontProperties hashing / copying
1 parent 5604109 commit 70dc0d1

1 file changed

Lines changed: 5 additions & 20 deletions

File tree

lib/matplotlib/font_manager.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,7 @@ def _from_any(cls, arg):
701701
return cls(**arg)
702702

703703
def __hash__(self):
704-
l = (tuple(self.get_family()),
705-
self.get_slant(),
706-
self.get_variant(),
707-
self.get_weight(),
708-
self.get_stretch(),
709-
self.get_size(),
710-
self.get_file(),
711-
self.get_math_fontfamily())
712-
return hash(l)
704+
return hash(tuple(self.__dict__.values()))
713705

714706
def __eq__(self, other):
715707
return hash(self) == hash(other)
@@ -725,7 +717,7 @@ def get_family(self):
725717
from their respective rcParams when searching for a matching font) in
726718
the order of preference.
727719
"""
728-
return self._family
720+
return list(self._family)
729721

730722
def get_name(self):
731723
"""
@@ -794,8 +786,8 @@ def set_family(self, family):
794786
"""
795787
family = mpl._val_or_rc(family, 'font.family')
796788
if isinstance(family, str):
797-
family = [family]
798-
self._family = family
789+
family = (family,)
790+
self._family = tuple(family)
799791

800792
def set_style(self, style):
801793
"""
@@ -958,14 +950,7 @@ def set_math_fontfamily(self, fontfamily):
958950
def __copy__(self):
959951
# Bypass __init__ for speed, since values are already validated
960952
new = FontProperties.__new__(FontProperties)
961-
new._family = self._family
962-
new._slant = self._slant
963-
new._variant = self._variant
964-
new._weight = self._weight
965-
new._stretch = self._stretch
966-
new._size = self._size
967-
new._file = self._file
968-
new._math_fontfamily = self._math_fontfamily
953+
new.__dict__.update(self.__dict__)
969954
return new
970955

971956
def copy(self):

0 commit comments

Comments
 (0)