Reading further from here I ran the code from standard python console rather than using jupyter, still didn't get correct result but better than earlier no error this time
dill.source.getsource(b)
Output I get is as below
'import dill\ndill.loads(b\'\\x80\\x03cdill._dill\\n_create_type\\nq\\x00(cdill._dill\\n_load_type\\nq\\x01X\\x04\\x00\\x00\\x00typeq\\x02\\x85q\\x03Rq\\x04X\\x03\\x00\\x00\\x00Fooq\\x05h\\x01X\\x06\\x00\\x00\\x00objectq\\x06\\x85q\\x07Rq\\x08\\x85q\\t}q\\n(X\\n\\x00\\x00\\x00__module__q\\x0bX\\x08\\x00\\x00\\x00__main__q\\x0cX\\x03\\x00\\x00\\x00barq\\rcdill._dill\\n_create_function\\nq\\x0e(h\\x01X\\x08\\x00\\x00\\x00CodeTypeq\\x0f\\x85q\\x10Rq\\x11(K\\x02K\\x00K\\x02K\\x02KCC\\n|\\x01|\\x00j\\x00\\x17\\x00S\\x00q\\x12N\\x85q\\x13X\\x01\\x00\\x00\\x00yq\\x14\\x85q\\x15X\\x04\\x00\\x00\\x00selfq\\x16X\\x01\\x00\\x00\\x00xq\\x17\\x86q\\x18X\\x07\\x00\\x00\\x00<stdin>q\\x19h\\rK\\x02C\\x02\\x00\\x01q\\x1a))tq\\x1bRq\\x1cc__builtin__\\n__main__\\nh\\rNN}q\\x1dtq\\x1eRq\\x1fh\\x14K\\x01X\\x07\\x00\\x00\\x00__doc__q NX\\r\\x00\\x00\\x00__slotnames__q!]q"utq#Rq$)\\x81q%.\')\n'
Further in the note suggestion was to use dill.source.getsource(dill.detect.code(b))
but this gives error as TypeError: None is not a module, class, method, function, traceback, frame, or code object
Then when I tried dill.source.getsource(b.bar)
I get perfect result
>>> dill.source.getsource(b.bar)
' def bar(self, x):\n return x+self.y \n'
Now something I got
What we can do is first trace the pickle file using below code, this will give a list of all functions in the class then we can individually detect their source code using getsource
.
dill.detect.trace(True)
dill.pickles(b)