The value of `self` as a (not serializable) `types.FunctionType` object

def value(self):
        """The value of `self` as a (not serializable) `types.FunctionType` object"""
        f = types.FunctionType(
            self.code.value, self.globals, self.name, self.defaults, self.closure
        )
        d = self.dict.copy()
        for attr in PY3_ATTRS:
            try:
                setattr(f, attr, d.pop(attr, None))
            except TypeError:
                pass
        for attr in OPT_ATTRS:
            val = d.pop(attr, _missing)
            if val is not _missing:
                setattr(f, attr, val)
        __self__ = d.pop('__self__', _missing)
        __class__ = d.pop('im_class', _missing)
        getattr(f, DICT_ATTR).update(d)
        if __self__ is not _missing:
            if METHOD_HAS_CLASS:
                if __class__ is _missing:
                    __class__ = __self__.__class__
                f = types.MethodType(f, __self__, __class__)
            else:
                f = types.MethodType(f, __self__)
                if __class__ is not _missing:
                    f.im_class = __class__
        return f