(evaluator, obj, arguments)
return ContextSet(ClassContext(evaluator, parent_context, generated_class))
Implementation of the namedtuple function.

    This has to be done by processing the namedtuple class template and
    evaluating the result.
Implementation of the namedtuple function.
Implementation of the namedtuple function .
def collections_namedtuple(evaluator, obj, arguments):
    """
    Implementation of the namedtuple function.

    This has to be done by processing the namedtuple class template and
    evaluating the result.

    """
    collections_context = obj.parent_context
    _class_template_set = collections_context.py__getattribute__(u'_class_template')
    if not _class_template_set:
        # Namedtuples are not supported on Python 2.6, early 2.7, because the
        # _class_template variable is not defined, there.
        return NO_CONTEXTS

    # Process arguments
    # TODO here we only use one of the types, we should use all.
    # TODO this is buggy, doesn't need to be a string
    name = list(_follow_param(evaluator, arguments, 0))[0].get_safe_value()
    _fields = list(_follow_param(evaluator, arguments, 1))[0]
    if isinstance(_fields, compiled.CompiledObject):
        fields = _fields.get_safe_value().replace(',', ' ').split()
    elif isinstance(_fields, iterable.Sequence):
        fields = [
            v.get_safe_value()
            for lazy_context in _fields.py__iter__()
            for v in lazy_context.infer() if is_string(v)
        ]
    else:
        return NO_CONTEXTS

    def get_var(name):
        x, = collections_context.py__getattribute__(name)
        return x.get_safe_value()

    base = next(iter(_class_template_set)).get_safe_value()
    base += _NAMEDTUPLE_INIT
    # Build source code
    code = base.format(
        typename=name,
        field_names=tuple(fields),
        num_fields=len(fields),
        arg_list=repr(tuple(fields)).replace("u'", "").replace("'", "")[1:-1],
        repr_fmt=', '.join(get_var(u'_repr_template').format(name=name) for name in fields),
        field_defs='\n'.join(get_var(u'_field_template').format(index=index, name=name)
                             for index, name in enumerate(fields))
    )

    # Parse source code
    module = evaluator.grammar.parse(code)
    generated_class = next(module.iter_classdefs())
    parent_context = ModuleContext(
        evaluator, module, None,
        code_lines=parso.split_lines(code, keepends=True),
    )
    return ContextSet(ClassContext(evaluator, parent_context, generated_class))
def collections_namedtuple ( evaluator , obj , arguments ) : collections_context = obj . parent_context _class_template_set = collections_context . py__getattribute__ ( u'_class_template' ) if not _class_template_set : # Namedtuples are not supported on Python 2.6, early 2.7, because the # _class_template variable is not defined, there. return NO_CONTEXTS # Process arguments # TODO here we only use one of the types, we should use all. # TODO this is buggy, doesn't need to be a string name = list ( _follow_param ( evaluator , arguments , 0 ) ) [ 0 ] . get_safe_value ( ) _fields = list ( _follow_param ( evaluator , arguments , 1 ) ) [ 0 ] if isinstance ( _fields , compiled . CompiledObject ) : fields = _fields . get_safe_value ( ) . replace ( ',' , ' ' ) . split ( ) elif isinstance ( _fields , iterable . Sequence ) : fields = [ v . get_safe_value ( ) for lazy_context in _fields . py__iter__ ( ) for v in lazy_context . infer ( ) if is_string ( v ) ] else : return NO_CONTEXTS def get_var ( name ) : x , = collections_context . py__getattribute__ ( name ) return x . get_safe_value ( ) base = next ( iter ( _class_template_set ) ) . get_safe_value ( ) base += _NAMEDTUPLE_INIT # Build source code code = base . format ( typename = name , field_names = tuple ( fields ) , num_fields = len ( fields ) , arg_list = repr ( tuple ( fields ) ) . replace ( "u'" , "" ) . replace ( "'" , "" ) [ 1 : - 1 ] , repr_fmt = ', ' . join ( get_var ( u'_repr_template' ) . format ( name = name ) for name in fields ) , field_defs = '\n' . join ( get_var ( u'_field_template' ) . format ( index = index , name = name ) for index , name in enumerate ( fields ) ) ) # Parse source code module = evaluator . grammar . parse ( code ) generated_class = next ( module . iter_classdefs ( ) ) parent_context = ModuleContext ( evaluator , module , None , code_lines = parso . split_lines ( code , keepends = True ) , ) return ContextSet ( ClassContext ( evaluator , parent_context , generated_class ) )