<div dir="ltr">Hello,<div><br></div><div>I would like to raise an issue here that I've been discussing at python-porting.</div><div><br></div><div>(And I'd like to preface by saying that I'm not intimately familiar with Python's innards, so if I make any mistakes please correct me.)</div>
<div><br></div><div>In Python 2.x there was an "unbound method" type. An unbound method would have an attribute `.im_class` that would refer to the class on which the method was defined. This allowed users to use the `copy_reg` module to pickle unbound methods by name. (In a similar way to how functions and classes are pickled by default.)</div>
<div><br></div><div>In Python 3.x unbound methods are plain functions. There is no way of knowing on which class they are defined, so therefore it's impossible to pickle them. It is even impossible to tell `copyreg` to use a custom reducer:</div>
<div><br></div><div>(To the people who wonder why would anyone want to pickle unbound methods: I know that it sounds like a weird thing to do. Keep in mind that sometimes your objects need to get pickled. For example if you're using the multiprocessing module, and you pass into it an object that somehow refers to an unbound method, then that method has to be picklable.)</div>
<div><br></div><div>The idea is: Let's give unbound methods an attribute that will refer to the class on which they were defined.</div><div><br></div><div>What do you think?</div><div><br></div><div><br>Ram.