# Examples from pyvista.allow_new_attributes
# ==========================================

# Get the default attribute mode.
import pyvista as pv
pv.allow_new_attributes()

# Setting new private attributes on PyVista objects is allowed by default.
mesh = pv.PolyData()
mesh._foo = 42  # OK
mesh.foo = 42  # ERROR

# Do not allow setting new attributes.
_ = pv.allow_new_attributes(False)
mesh._foo = 42  # ERROR
mesh.foo = 42  # ERROR

# Note that this state is global and will persist between function calls. Set it
# back to its original state explicitly.
_ = pv.allow_new_attributes('private')

# Use it as a context manager instead. This way, the state is only temporarily
# modified and is automatically restored.
with pv.allow_new_attributes(True):
    mesh._foo = 42  # OK
    mesh.foo = 42  # OK

pv.allow_new_attributes()

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code

