8000 Deduplicate docstrings and validation for set_alpha. · matplotlib/matplotlib@69974c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 69974c1

Browse files
committed
Deduplicate docstrings and validation for set_alpha.
... by moving everything to the base class. Note that Artist.set_alpha() clearly needs to accept None as well (given that Collection.set_alpha can pass None to it).
1 parent 9faf231 commit 69974c1

File tree

4 files changed

+8
-39
lines changed

4 files changed

+8
-39
lines changed

lib/matplotlib/artist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,10 @@ def set_alpha(self, alpha):
879879
880880
Parameters
881881
----------
882-
alpha : float
882+
alpha : float or None
883883
"""
884+
if alpha is not None and not isinstance(alpha, Number):
885+
raise TypeError('alpha must be a float or None')
884886
self._alpha = alpha
885887
self.pchanged()
886888
self.stale = True

lib/matplotlib/collections.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,20 +728,9 @@ def set_edgecolor(self, c):
728728
self._set_edgecolor(c)
729729

730730
def set_alpha(self, alpha):
731-
"""
732-
Set the alpha transparencies of the collection.
733-
734-
Parameters
735-
----------
736-
alpha : float or None
737-
"""
738-
if alpha is not None:
739-
try:
740-
float(alpha)
741-
except TypeError:
742-
raise TypeError('alpha must be a float or None')
731+
# docstring inherited
732+
super().set_alpha(alpha)
743733
self.update_dict['array'] = True
744-
artist.Artist.set_alpha(self, alpha)
745734
self._set_facecolor(self._original_facecolor)
746735
self._set_edgecolor(self._original_edgecolor)
747736

lib/matplotlib/patches.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,8 @@ def set_color(self, c):
328328
self.set_edgecolor(c)
329329

330330
def set_alpha(self, alpha):
331-
"""
332-
Set the alpha transparency of the patch.
333-
334-
Parameters
335-
----------
336-
alpha : float or None
337-
"""
338-
if alpha is not None:
339-
try:
340-
float(alpha)
341-
except TypeError:
342-
raise TypeError('alpha must be a float or None')
343-
artist.Artist.set_alpha(self, alpha)
331+
# docstring inherited
332+
super().set_alpha(alpha)
344333
self._set_facecolor(self._original_facecolor)
345334
self._set_edgecolor(self._original_edgecolor)
346335
# stale is already True

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -744,18 +744,7 @@ def set_edgecolor(self, colors):
744744
self._edgecolors3d = PolyCollection.get_edgecolor(self)
745745

746746
def set_alpha(self, alpha):
747-
"""
748-
Set the alpha transparencies of the collection.
749-
750-
Parameters
751-
----------
752-
alpha : float or None
753-
"""
754-
if alpha is not None:
755-
try:
756-
float(alpha)
757-
except TypeError:
758-
raise TypeError('alpha must be a float or None')
747+
# docstring inherited
759748
artist.Artist.set_alpha(self, alpha)
760749
try:
761750
self._facecolors3d = mcolors.to_rgba_array(

0 commit comments

Comments
 (0)
0