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

Skip to content

Commit 893e7cf

Browse files
ericpretimhoffm
andauthored
Simplify syntax and improve readability
Co-authored-by: Tim Hoffmann <[email protected]>
1 parent cee023e commit 893e7cf

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ def onselect(epress, erelease):
106106

107107
artist = tool._selection_artist
108108
assert artist.get_facecolor() == mcolors.to_rgba('b', alpha=0.2)
109-
props = dict(facecolor='r', alpha=0.3)
110-
tool.set_props(**props)
111-
assert artist.get_facecolor() == mcolors.to_rgba(*props.values())
109+
tool.set_props(facecolor='r', alpha=0.3)
110+
assert artist.get_facecolor() == mcolors.to_rgba('r', alpha=0.3)
112111

113112
for artist in tool._handles_artists:
114113
assert artist.get_markeredgecolor() == 'black'
115114
assert artist.get_alpha() == 0.5
116-
handle_props = dict(markeredgecolor='r', alpha=0.3)
117-
tool.set_handle_props(**handle_props)
115+
tool.set_handle_props(markeredgecolor='r', alpha=0.3)
118116
for artist in tool._handles_artists:
119117
assert artist.get_markeredgecolor() == 'r'
120118
assert artist.get_alpha() == 0.3
@@ -450,15 +448,13 @@ def onselect(epress, erelease):
450448

451449
artist = tool._selection_artist
452450
assert artist.get_facecolor() == mcolors.to_rgba('b', alpha=0.2)
453-
props = dict(facecolor='r', alpha=0.3)
454-
tool.set_props(**props)
455-
assert artist.get_facecolor() == mcolors.to_rgba(*props.values())
451+
tool.set_props(facecolor='r', alpha=0.3)
452+
assert artist.get_facecolor() == mcolors.to_rgba('r', alpha=0.3)
456453

457454
for artist in tool._handles_artists:
458455
assert artist.get_color() == 'b'
459456
assert artist.get_alpha() == 0.5
460-
handle_props = dict(color='r', alpha=0.3)
461-
tool.set_handle_props(**handle_props)
457+
tool.set_handle_props(color='r', alpha=0.3)
462458
for artist in tool._handles_artists:
463459
assert artist.get_color() == 'r'
464460
assert artist.get_alpha() == 0.3
@@ -865,16 +861,14 @@ def onselect(vertices):
865861
artist = tool._selection_artist
866862
assert artist.get_color() == 'b'
867863
assert artist.get_alpha() == 0.2
868-
props = dict(color='r', alpha=0.3)
869-
tool.set_props(**props)
870-
assert artist.get_color() == props['color']
871-
assert artist.get_alpha() == props['alpha']
864+
tool.set_props(color='r', alpha=0.3)
865+
assert artist.get_color() == 'r'
866+
assert artist.get_alpha() == 0.3
872867

873868
for artist in tool._handles_artists:
874869
assert artist.get_color() == 'b'
875870
assert artist.get_alpha() == 0.5
876-
handle_props = dict(color='r', alpha=0.3)
877-
tool.set_handle_props(**handle_props)
871+
tool.set_handle_props(color='r', alpha=0.3)
878872
for artist in tool._handles_artists:
879873
assert artist.get_color() == 'r'
880874
assert artist.get_alpha() == 0.3

lib/matplotlib/widgets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,10 +2011,8 @@ def set_visible(self, visible):
20112011
@property
20122012
def artists(self):
20132013
"""Tuple of the artists of the selector."""
2014-
if getattr(self, '_handles_artists', None) is not None:
2015-
return (self._selection_artist, *self._handles_artists)
2016-
else:
2017-
return (self._selection_artist, )
2014+
handles_artists = getattr(self, '_handles_artists', ())
2015+
return (self._selection_artist,) + handles_artists
20182016

20192017
def set_props(self, **props):
20202018
"""
@@ -2245,6 +2243,8 @@ def _setup_edge_handles(self, props):
22452243
def _handles_artists(self):
22462244
if self._edge_handles is not None:
22472245
return self._edge_handles.artists
2246+
else:
2247+
return ()
22482248

22492249
def _set_cursor(self, enabled):
22502250
"""Update the canvas cursor based on direction of the selector."""

0 commit comments

Comments
 (0)