def rectagtuple(typename,
                meta_field_names,
                sub_field_names,
                verbose=False):

    # currently no validation of field names
    assert (type(meta_field_names) is tuple and
            all(type(x) is str for x in meta_field_names))
    assert (type(sub_field_names) is tuple and
            all(type(x) is str for x in sub_field_names))

    if len(sub_field_names) > 0 and sub_field_names[-1][0] == '*':
        variadic = sub_field_names[-1][1:]
    else:
        variadic = None

    # Fill-in the class template
    n_meta = len(meta_field_names)
    meta_arg_list = ''.join(
        '{}, '.format(x) for x in meta_field_names
    )
    sub_arg_list = ', '.join(sub_field_names)
    field_defs = '\n'.join(
        [_meta_field_template.format(index=index, name=name)
         for index, name in enumerate(meta_field_names)] +
        [_sub_field_template.format(index=index + n_meta, name=name)
         for index, name in enumerate(sub_field_names)
         if name[0] != '*'] +
        [_variadic_field_template.format(index=index + n_meta, name=name[1:])
         for index, name in enumerate(sub_field_names)
         if name[0] == '*']
     )
    class_definition = _class_template.format(
        typename=typename,
        meta_field_names=meta_field_names,
        sub_field_names=sub_field_names,
        n_meta=n_meta,
        meta_arg_list=meta_arg_list,
        sub_arg_list=sub_arg_list,
        field_defs=field_defs,
    )

    if verbose:
        print class_definition

    # Execute the template string in a temporary namespace and support
    # tracing utilities by setting a value for
    # frame.f_globals['__name__']
    namespace = dict(__name__='rectagtuple_{}'.format(typename),
                     _tupler=_tupler,
                     _tuple=tuple,
                     #_itemgetter=itemgetter,
                     _itemgetter=_itemgetter,
                     _property=property,
                     _islice=islice,
                 )
    try:
        exec class_definition in namespace
    except SyntaxError as e:
        raise SyntaxError(e.message + ':\n' + class_definition)
    result = namespace[typename]

    # For pickling to work, the __module__ variable needs to be set to the frame
    # where the named tuple is created.  Bypass this step in environments where
    # sys._getframe is not defined (Jython for example) or sys._getframe is not
    # defined for arguments greater than 0 (IronPython).
    try:
        result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
    except (__HOLE__, ValueError):
        pass

    return result
dataset/ETHPy150Open Microsoft/ivy/ivy/utils/try3.py/rectagtuple