Skip to content

Commit 4b99bc6

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 22fd053 commit 4b99bc6

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/matplotlib/collections.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,16 @@ def set_capstyle(self, cs):
641641
"""
642642
self._capstyle = CapStyle(cs)
643643

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

647655
@_docstring.interpd
648656
def set_joinstyle(self, js):
@@ -655,8 +663,16 @@ def set_joinstyle(self, js):
655663
"""
656664
self._joinstyle = JoinStyle(js)
657665

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

661677
@staticmethod
662678
def _bcast_lwls(linewidths, dashes):

lib/matplotlib/collections.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class Collection(artist.Artist, cm.ScalarMappable):
5151
def set_linewidth(self, lw: float | Sequence[float]) -> None: ...
5252
def set_linestyle(self, ls: LineStyleType | Sequence[LineStyleType]) -> None: ...
5353
def set_capstyle(self, cs: CapStyleType) -> None: ...
54-
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
54+
def get_capstyle(self) -> Literal["butt", "projecting", "round"] | None: ...
5555
def set_joinstyle(self, js: JoinStyleType) -> None: ...
56-
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
56+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"] | None: ...
5757
def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ...
5858
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...
5959
def set_facecolor(self, c: ColorType | Sequence[ColorType]) -> None: ...

lib/matplotlib/tests/test_collections.py

+4
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ def test_set_wrong_linestyle():
625625

626626
@mpl.style.context('default')
627627
def test_capstyle():
628+
col = mcollections.PathCollection([])
629+
assert col.get_capstyle() is None
628630
col = mcollections.PathCollection([], capstyle='round')
629631
assert col.get_capstyle() == 'round'
630632
col.set_capstyle('butt')
@@ -633,6 +635,8 @@ def test_capstyle():
633635

634636
@mpl.style.context('default')
635637
def test_joinstyle():
638+
col = mcollections.PathCollection([])
639+
assert col.get_joinstyle() is None
636640
col = mcollections.PathCollection([], joinstyle='round')
637641
assert col.get_joinstyle() == 'round'
638642
col.set_joinstyle('miter')

0 commit comments

Comments
 (0)