Python3.12 user-defined immortal objects

The concept of immortal objects was introduced since PEP 683. I saw many internal objects (such as small ints, None, strings, etc.) have been made immortal, but I wonder if it is possible to make a user-defined object immortal in the current Python versions? If not, what could be a workaround?

For example,

class MyClass:
    def __init__(self, x):
        self._x = x

mycls = MyClass(3)
# Does there exist or would there be some public API to make `mycls` immortal?
sys.setimmortal(mycls) # for example

I do not know, but in the Scope section it says

Object immortality is meant to be an internal-only feature, so this proposal does not include any changes to public API or behavior (with one exception).

1 Like

Thanks for the info!