Skip to content
Closed
Changes from all commits
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
3 changes: 2 additions & 1 deletion mne/viz/_brain/_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def __init__(
)
self._layered_meshes[h] = mesh
# add metadata to the mesh for picking
mesh._polydata._hemi = h
# using __setattr__ is needed to set dynamic properties for PolyData
object.__setattr__(mesh._polydata, "_hemi", h)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can't this be setattr(mesh._polydata, "_hemi", h)? If that works, I would prefer to avoid calling a private dunder method.

Copy link
Copy Markdown
Contributor Author

@user27182 user27182 Jul 17, 2025

Choose a reason for hiding this comment

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

No it must use object.__setattr__ to work. The changes upstream explicitly forbids setting new attributes the "normal" way.

This change can be considered temporary in order to get our CI integration tests passing upstream. Once the change upstream is formalized and a new PyVista release is made, there will be a formal API for this, e.g.

- mesh._polydata._hemi = h
+ with pv.allow_new_attributes():
+    mesh._polydata._hemi = h

If you'd like I can add a TODO or open a new issue to track this. But in the interim this is needed for our MNE integration tests to pass.

Copy link
Copy Markdown
Contributor

@wmvanvliet wmvanvliet Jul 18, 2025

Choose a reason for hiding this comment

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

Thanks for the clarification. #13330 is a cleaner way to do this, but thanks for putting in the effort.

else:
actor = self._layered_meshes[h]._actor
self._renderer.plotter.add_actor(actor, render=False)
Expand Down
Loading