def __new__(cls, f, module=None, *args):
        """
        Creates a new `SerializableFunction` instance.

        :param f: The function to decompose into a serializable form
        :type f: types.FunctionType
        :param module: Name of the module of the function (To be imported for global variables when calling).
          Leave blank to get from function (Not recommended, as it might be wrong (e.g., `"__main__"`))
        :type module: Optional[str]
        :param args: This should be ignored.
          It is used to allow `SerializableFunction(*serialized_function)` (i.e., when unpickling)
        :return: A new object that can be serialized and called
        :rtype: SerializableFunction
        """
        if args:
            if len(args) == 4:
                # When unpickling, all of the attributes are given as arguments
                return super(SerializableFunction, cls).__new__(cls, f, module, *args)
            raise TypeError('__new__() takes 1 positional argument but {} were given'.format(
                len(args) + 1
            ))
        if isinstance(f, types.MethodType):
            self = cls.__new__(cls, getattr(f, METHOD_FUNC_ATTR), module)
            self.dict['__self__'] = getattr(f, METHOD_SELF_ATTR)
            if METHOD_HAS_CLASS:
                self.dict['im_class'] = f.im_class
            return self
        code = SerializableCode(getattr(f, CODE_ATTR))
        if module is None:
            module = f.__module__
        name = getattr(f, NAME_ATTR)
        defaults = getattr(f, DEFAULTS_ATTR)
        closure = getattr(f, CLOSURE_ATTR)

        d = dict(getattr(f, DICT_ATTR))
        for attr in PY3_ATTRS:
            d[attr] = getattr(f, attr, None)

        for attr in OPT_ATTRS:
            val = getattr(f, attr, _missing)
            if val is not _missing:
                d[attr] = val

        return super(SerializableFunction, cls).__new__(
            cls, code, module, name, defaults, closure, d
        )
def __new__ ( cls , f , module = None , * args ) : if args : if len ( args ) == 4 : return super ( SerializableFunction , cls ) . __new__ ( cls , f , module , * args ) raise TypeError ( '__new__() takes 1 positional argument but {} were given' . format ( len ( args ) + 1 ) ) if isinstance ( f , types . MethodType ) : self = cls . __new__ ( cls , getattr ( f , METHOD_FUNC_ATTR ) , module ) self . dict [ '__self__' ] = getattr ( f , METHOD_SELF_ATTR ) if METHOD_HAS_CLASS : self . dict [ 'im_class' ] = f . im_class return self code = SerializableCode ( getattr ( f , CODE_ATTR ) ) if module is None : module = f . __module__ name = getattr ( f , NAME_ATTR ) defaults = getattr ( f , DEFAULTS_ATTR ) closure = getattr ( f , CLOSURE_ATTR ) d = dict ( getattr ( f , DICT_ATTR ) ) for attr in PY3_ATTRS : d [ attr ] = getattr ( f , attr , None ) for attr in OPT_ATTRS : val = getattr ( f , attr , _missing ) if val is not _missing : d [ attr ] = val return super ( SerializableFunction , cls ) . __new__ ( cls , code , module , name , defaults , closure , d )
Creates a new `SerializableFunction` instance.

        :param f: The function to decompose into a serializable form
        :type f: types.FunctionType
        :param module: Name of the module of the function (To be imported for global variables when calling).
          Leave blank to get from function (Not recommended, as it might be wrong (e.g., `"__main__"`))
        :type module: Optional[str]
        :param args: This should be ignored.
          It is used to allow `SerializableFunction(*serialized_function)` (i.e., when unpickling)
        :return: A new object that can be serialized and called
        :rtype: SerializableFunction