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

Skip to content

Commit 0ea5fff

Browse files
committed
MNT: use ordereddict to order args in setp
Make one call to `update` with the ordered dict rather than one call per element.
1 parent bba3ae2 commit 0ea5fff

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/matplotlib/artist.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unicode_literals)
33

44
from matplotlib.externals import six
5+
from collections import OrderedDict
56

67
import re
78
import warnings
@@ -1451,17 +1452,16 @@ def setp(obj, *args, **kwargs):
14511452
if not cbook.iterable(obj):
14521453
objs = [obj]
14531454
else:
1454-
objs = cbook.flatten(obj)
1455+
objs = list(cbook.flatten(obj))
14551456

14561457
if len(args) % 2:
14571458
raise ValueError('The set args must be string, value pairs')
14581459

1459-
funcvals = []
1460+
# put args into ordereddict to maintain order
1461+
funcvals = OrderedDict()
14601462
for i in range(0, len(args) - 1, 2):
1461-
funcvals.append((args[i], args[i + 1]))
1462-
# do the *args one at a time to ensure order
1463-
ret = [o.update({s: val}) for s, val in funcvals for o in objs]
1464-
# apply kwargs in bulk
1463+
funcvals[args[i]] = args[i + 1]
1464+
ret = [o.update(funcvals) for o in objs]
14651465
ret.extend([o.update(kwargs) for o in objs])
14661466
return [x for x in cbook.flatten(ret)]
14671467

0 commit comments

Comments
 (0)