{"action":"created","issue":{"url":"https://api.github.com/repos/uqfoundation/dill/issues/135","labels_url":"https://api.github.com/repos/uqfoundation/dill/issues/135/labels{/name}","comments_url":"https://api.github.com/repos/uqfoundation/dill/issues/135/comments","events_url":"https://api.github.com/repos/uqfoundation/dill/issues/135/events","html_url":"https://github.com/uqfoundation/dill/issues/135","id":115544537,"number":135,"title":"Pickling inner/nested classes fails","user":{"login":"jakirkham","id":3019665,"avatar_url":"https://avatars.githubusercontent.com/u/3019665?v=3","gravatar_id":"","url":"https://api.github.com/users/jakirkham","html_url":"https://github.com/jakirkham","followers_url":"https://api.github.com/users/jakirkham/followers","following_url":"https://api.github.com/users/jakirkham/following{/other_user}","gists_url":"https://api.github.com/users/jakirkham/gists{/gist_id}","starred_url":"https://api.github.com/users/jakirkham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakirkham/subscriptions","organizations_url":"https://api.github.com/users/jakirkham/orgs","repos_url":"https://api.github.com/users/jakirkham/repos","events_url":"https://api.github.com/users/jakirkham/events{/privacy}","received_events_url":"https://api.github.com/users/jakirkham/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/uqfoundation/dill/labels/duplicate","name":"duplicate","color":"cccccc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-11-06T16:52:40Z","updated_at":"2015-11-09T13:29:49Z","closed_at":"2015-11-06T19:39:23Z","body":"Supposing I have a module like below.\r\n\r\n    ### nest.py\r\n    class A(object):\r\n        class B(object):\r\n            pass\r\n\r\n    # B = A.B\r\n\r\nIf I run this, all is well.\r\n\r\n    >>> import dill\r\n    >>> from nest import A\r\n    >>> dill.loads(dill.dumps(A))\r\n    nest.A\r\n\r\nHowever, if I run this, everything comes to a halt. For a workaround, one can uncomment the line at the end of the module.\r\n\r\n    >>> dill.loads(dill.dumps(A.B))\r\n    ---------------------------------------------------------------------------\r\n    PicklingError                             Traceback (most recent call last)\r\n    <ipython-input-3-34901c70ec52> in <module>()\r\n    ----> 1 dill.loads(dill.dumps(A.B))\r\n    \r\n    /opt/conda/lib/python2.7/site-packages/dill/dill.pyc in dumps(obj, protocol, byref, fmode, recurse)\r\n        190     \"\"\"pickle an object to a string\"\"\"\r\n        191     file = StringIO()\r\n    --> 192     dump(obj, file, protocol, byref, fmode, recurse)#, strictio)\r\n        193     return file.getvalue()\r\n        194 \r\n    \r\n    /opt/conda/lib/python2.7/site-packages/dill/dill.pyc in dump(obj, file, protocol, byref, fmode, recurse)\r\n        184             return\r\n        185     # end hack\r\n    --> 186     pik.dump(obj)\r\n        187     return\r\n        188 \r\n    \r\n    /opt/conda/lib/python2.7/pickle.pyc in dump(self, obj)\r\n        222         if self.proto >= 2:\r\n        223             self.write(PROTO + chr(self.proto))\r\n    --> 224         self.save(obj)\r\n        225         self.write(STOP)\r\n        226 \r\n    \r\n    /opt/conda/lib/python2.7/pickle.pyc in save(self, obj)\r\n        284         f = self.dispatch.get(t)\r\n        285         if f:\r\n    --> 286             f(self, obj) # Call unbound method with explicit self\r\n        287             return\r\n        288 \r\n    \r\n    /opt/conda/lib/python2.7/site-packages/dill/dill.pyc in save_type(pickler, obj)\r\n       1100        #print (\"%s\\n%s\" % (type(obj), obj.__name__))\r\n       1101        #print (\"%s\\n%s\" % (obj.__bases__, obj.__dict__))\r\n    -> 1102         StockPickler.save_global(pickler, obj)\r\n       1103     return\r\n       1104 \r\n    \r\n    /opt/conda/lib/python2.7/pickle.pyc in save_global(self, obj, name, pack)\r\n        746             raise PicklingError(\r\n        747                 \"Can't pickle %r: it's not found as %s.%s\" %\r\n    --> 748                 (obj, module, name))\r\n        749         else:\r\n        750             if klass is not obj:\r\n    \r\n    PicklingError: Can't pickle <class 'nest.B'>: it's not found as nest.B\r\n"},"comment":{"url":"https://api.github.com/repos/uqfoundation/dill/issues/comments/155061890","html_url":"https://github.com/uqfoundation/dill/issues/135#issuecomment-155061890","issue_url":"https://api.github.com/repos/uqfoundation/dill/issues/135","id":155061890,"user":{"login":"mmckerns","id":321534,"avatar_url":"https://avatars.githubusercontent.com/u/321534?v=3","gravatar_id":"","url":"https://api.github.com/users/mmckerns","html_url":"https://github.com/mmckerns","followers_url":"https://api.github.com/users/mmckerns/followers","following_url":"https://api.github.com/users/mmckerns/following{/other_user}","gists_url":"https://api.github.com/users/mmckerns/gists{/gist_id}","starred_url":"https://api.github.com/users/mmckerns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmckerns/subscriptions","organizations_url":"https://api.github.com/users/mmckerns/orgs","repos_url":"https://api.github.com/users/mmckerns/repos","events_url":"https://api.github.com/users/mmckerns/events{/privacy}","received_events_url":"https://api.github.com/users/mmckerns/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T13:29:49Z","updated_at":"2015-11-09T13:29:49Z","body":"@jakirkham: Yes, that is something like what is needed.  It only works for objects defined within a file, however `dill.source` should be able to extend it to work in `__main__`.  I'll have a look at it, and maybe `dill.source` includes most of what `qualname` is doing already.  Thanks for the pointer."}}