8000 artist.axes and .figure should never be reassignable · Issue #6793 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
artist.axes and .figure should never be reassignable #6793
Closed
@anntzer

Description

@anntzer

#3835 ensured that the .axes attribute of an artist cannot be assigned to a new Axes when it is already set to an earlier Axes. However, it does not prevent one from doing so by going via None. Also, nothing is done regarding reassignment of .figure.

In practice there's plenty of code that assumes these invariants (see #6785 for how I ended up here), so I'd suggest tightening the restrictions to

  • .axes can only ever be set to a non-None value once. Upon removal of the artist from an axes, the private attribute ._discarded is set to prevent further reuse. (If there is truly need for it, we could add a .copy() method that would return, well, a copy of the artist, but with ._discarded unset, so that it can be reassigned to a new Axes.)
  • .figure follows the same rules, and is additionally automatically set/unset whenever .axes is set/unset.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0