Go from jit::ClassDef to python code?

I’m looking at this example

Is it possible to get Python code from the classDef, to loosely recover the testSource? I read pytorch/serialization.md at master · pytorch/pytorch · GitHub but don’t know where to go for C++ code. This is something close pytorch/script_init.cpp at 51e50a2ddb9844e0abaf6028fe5e4246448dffff · pytorch/pytorch · GitHub

Should I copy this code into a function to achieve my goal? Right now it’s just in a python binding that I can’t use.

Suppose I do that, then I will have an instance of a ClassDef.

Then I could try PythonPrint to print the Python code: https://github.com/pytorch/pytorch/blob/91ef3c82615d6ede05d5b86f1bd5571ea95e4ef1/torch/csrc/jit/python/script_init.cpp#L1235-L1243 I noticed that PythonPrint is missing printClass whereas PythonPrintImpl does have printClass. So I would have to use PythonPrintImpl or duplicate its code, both seem wrong to do.