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

Skip to content

Commit 2f4f08e

Browse files
committed
Fix default return of Collection.get_{cap,join}style
If neither are specified at object creation, the default is to be `None`. This broke `get_{cap,join}style` when the enum wrappers were created as they assume the internal value is always an enum value.
1 parent 5a89bdb commit 2f4f08e

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/matplotlib/collections.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,16 @@ def set_capstyle(self, cs):
639639
"""
640640
self._capstyle = CapStyle(cs)
641641

642+
@_docstring.interpd
642643
def get_capstyle(self):
643-
return self._capstyle.name
644+
"""
645+
Return the cap style for the collection (for all its elements).
646+
647+
Returns
648+
-------
649+
%(CapStyle)s or None
650+
"""
651+
return self._capstyle.name if self._capstyle else None
644652

645653
@_docstring.interpd
646654
def set_joinstyle(self, js):
@@ -653,8 +661,16 @@ def set_joinstyle(self, js):
653661
"""
654662
self._joinstyle = JoinStyle(js)
655663

664+
@_docstring.interpd
656665
def get_joinstyle(self):
657-
return self._joinstyle.name
666+
"""
667+
Return the join style for the collection (for all its elements).
668+
669+
Returns
670+
-------
671+
%(JoinStyle)s or None
672+
"""
673+
return self._joinstyle.name if self._joinstyle else None
658674

659675
@staticmethod
660676
def _bcast_lwls(linewidths, dashes):

lib/matplotlib/collections.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ class Collection(artist.Artist, cm.ScalarMappable):
5252
def set_linewidth(self, lw: float | Sequence[float]) -> None: ...
5353
def set_linestyle(self, ls: LineStyleType | Sequence[LineStyleType]) -> None: ...
5454
def set_capstyle(self, cs: CapStyleType) -> None: ...
55-
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
55+
def get_capstyle(self) -> Literal["butt", "projecting", "round"] | None: ...
5656
def set_joinstyle(self, js: JoinStyleType) -> None: ...
57-
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
57+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"] | None: ...
5858
def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ...
5959
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...
6060
def set_facecolor(self, c: ColorType | Sequence[ColorType]) -> None: ...

lib/matplotlib/tests/test_collections.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ def test_set_wrong_linestyle():
620620

621621
@mpl.style.context('default')
622622
def test_capstyle():
623+
col = mcollections.PathCollection([])
624+
assert col.get_capstyle() is None
623625
col = mcollections.PathCollection([], capstyle='round')
624626
assert col.get_capstyle() == 'round'
625627
col.set_capstyle('butt')
@@ -628,6 +630,8 @@ def test_capstyle():
628630

629631
@mpl.style.context('default')
630632
def test_joinstyle():
633+
col = mcollections.PathCollection([])
634+
assert col.get_joinstyle() is None
631635
col = mcollections.PathCollection([], joinstyle='round')
632636
assert col.get_joinstyle() == 'round'
633637
col.set_joinstyle('miter')

0 commit comments

Comments
 (0)