Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MNT: unify code path of set, update, setp #5599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 14, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MNT: move helper function into update
Hide private helper method more thoroughly.
  • Loading branch information
tacaswell committed Dec 1, 2015
commit 3401a5d7e04c7738a6dfab108a8849721d653162
57 changes: 26 additions & 31 deletions 57 lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,35 @@ def update(self, props):
Update the properties of this :class:`Artist` from the
dictionary *prop*.
"""
def _update_property(self, k, v):
"""sorting out how to update property (setter or setattr)

Parameters
----------
k : str
The name of property to update
v : obj
The value to assign to the property
Returns
-------
ret : obj or None
If using a `set_*` method return it's return, else None.
"""
k = k.lower()
# white list attributes we want to be able to update through
# art.update, art.set, setp
if k in {'axes'}:
return setattr(self, k, v)
else:
func = getattr(self, 'set_' + k, None)
if func is None or not six.callable(func):
raise AttributeError('Unknown property %s' % k)
return func(v)

store = self.eventson
self.eventson = False
try:
ret = [self._update_property(k, v)
ret = [_update_property(self, k, v)
for k, v in sorted(props.items(), reverse=True)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sorting by key name is just to prevent any non-deterministic behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and makes color/facecolor/edgecolor go in the right order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly. It is also to have a priority structure. If someone defines both
"color" and "facecolor" at the same time, the current behavior is for color
to take precedence over facecolor, IIRC.

On Tue, Dec 1, 2015 at 11:51 AM, Michael Droettboom <
notifications@github.com> wrote:

In lib/matplotlib/artist.py
#5599 (comment):

@@ -845,21 +845,46 @@ def update(self, props):
"""
store = self.eventson
self.eventson = False

  •    changed = False
    
  •    try:
    
  •        ret = [self._update_property(k, v)
    
  •               for k, v in sorted(props.items(), reverse=True)]
    

The sorting by key name is just to prevent any non-deterministic behavior?


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5599/files#r46304017.

finally:
self.eventson = store
Expand All @@ -856,36 +881,6 @@ def update(self, props):
self.stale = True
return ret

def _update_property(self, k, v):
"""helper function for set, update, setp

This function takes care of sorting out if this should be done
through a `set_*` method or a property.

Parameters
----------
k : str
The property to update

v : obj
The value to assign to the property

Returns
-------
ret : obj or None
If using a `set_*` method return it's return, else return None.
"""
k = k.lower()
# white list attributes we want to be able to update through
# art.update, art.set, setp
if k in ['axes']:
return setattr(self, k, v)
else:
func = getattr(self, 'set_' + k, None)
if func is None or not six.callable(func):
raise AttributeError('Unknown property %s' % k)
return func(v)

def get_label(self):
"""
Get the label used for this artist in the legend.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.