Calling pure python method of jitclass instance

Sometimes I want to define and call pure python method of jitclass instance in python context because there can be a method that is intended to be called in python context and hard to be implemented without using pure python code.

Below is a simple example.

from numba.experimental import jitclass


def some_pure_python_function1():
    ...


def some_pure_python_function2():
    ...


@jitclass
class A:
    def __init__(self):
        pass

    # Do some heavy computation in numba context. Implementation is omitted
    def compute(self):
        pass

    # Pure python method
    def pretty_print(self):
        some_pure_python_function1()


@jitclass
class B:
    def __init__(self):
        pass

    # Do some heavy computation in numba context. Implementation is omitted
    def compute(self):
        pass

    # Pure python method
    def pretty_print(self):
        some_pure_python_function2()


def compute_and_print(v):
    """
    
    :param v: instance of any class that defines compute(self) and pretty_print(self) method
    :return: 
    """
    v.compute()

    v.pretty_print()  # Throw TypeError for instance of A and B


a = A()
b = B()

compute_and_print(a)  # Doesn't work
compute_and_print(b)  # Doesn't work

I is there any way to do this?

If there is any way to get underlying python class from jitclass, the line v.pretty_print() can be replaced by something like this : get_pyclass(v.__class__).pretty_print(v) which works on python context but I’m not sure if it is possible to get underlying python class from jitclass.

Can you use objmode, like

    def pretty_print(self):
        with numba.objmode:
            some_pure_python_function2()

Thanks for the suggestion. Actually I’m doing so currently.