Modifying structref properties from normal python code and jitcode

in the online docs there’s an example of modifying the structref from jitted code like

@njit
def make_bob():
    bob = MyStruct("unnamed", vector=np.zeros(3))
    # Mutate the attributes
    bob.name = "Bob"
    bob.vector = np.random.random(3)
    return bob

This works fine. It doesn’t work in plain-python- if I remove the ‘@njit’, I get

AttributeError: can’t set attribute

I can make a separate setter function, like

    def set_name(self, name):
        MyStruct_set_name(self, name)

and

@njit
def MyStruct_set_name(self, name):
    self.name = name
    return self.name

This works fine in plain python but fails when jitted

@njit
def make_bob() -> MyStruct:
    bob = MyStruct("unnamed", vector=np.zeros(3))
    # Mutate the attributes
    bob.name = "Bob"
    bob.set_name('Ted')  # fails here, Unknown attribute 'set_name' of type numba.MyStructType...
    bob.vector = np.random.random(3)
    return bob

So I have one way to modify the struct in jit mode and a different way to do it with plain python. Is there any way that works for both modes?

I’ve since learned that one can make two implementations, one a member function for python usages and one an overload for jit usages. This does achieve the goal of the post, but feels inelegant… I effectively end up implementing the function three times. First for the ‘real’ implementation, then a class method implementation and an overload implementation.