MNT: Discourage Artist.update#30978
Conversation
|
I do not see an error with v3.10.7 In [1]: import matplotlib.pyplot as plt
In [2]: line, = plt.plot([0, 1])
In [3]: line.update({'lw': 3})
Out[3]: [None] |
|
Contrary to updated PR summary, In [1]: import matplotlib.pyplot as plt
In [2]: fig = plt.figure()
In [3]: fig.set(lw=1)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 fig.set(lw=1)
<snip>
AttributeError: Figure.set() got an unexpected keyword argument 'lw' |
|
We should hold this until #30979 is in, because that noted difference in normalization will vanish. To be checked, but it may be that they aren't really different, which would affect our future intention on the function. It may be that they are behaviourally identical and we simply discourage the use of update. |
|
@timhoffm I see #30979 has been approved! Once that merges, set() and update() will essentially be identical (both relying on explicit alias setters). When that happens, I will rewrite this docstring to simply state that update is functionally equivalent to set (accepting a dictionary instead of kwargs), and I'll remove the warning about normalization since it will no longer apply. |
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
|
Thanks for clarification @timhoffm |
timhoffm
left a comment
There was a problem hiding this comment.
I approve, but would like to have a second approval, because the idea to discourage update() is mine.
PR summary
Clarified in the docstring that
Artist.updateis not strictly equivalent toArtist.set.Recent discussions (and findings in #30979) confirm two key behavioral differences:
updateskips property name normalization. It requires the correspondingset_<name>method to explicitly exist on the object (whereassetmaps aliases to canonical names).updateskips duplicate alias checks. If{'lw': 1, 'linewidth': 2}is passed,updateallows the last value to win, whereassetraises aTypeError.This updates the documentation to explicitly state that
updateacts as a raw, unvalidated interface compared to the safersetmethod.PR checklist