class ConstructorMutableAttribsLineNumberFixture:
    definition_is_none = None
    definition_is_not_a_function = _ast.Pass
    constructor_with_empty_body = _ast.FunctionDef(name='__init__', body=[])
    try:
        constructor_with_immutable = _ast.FunctionDef(
            name='__init__',
            body=[
                _ast.Assign(lineno=1, value=_ast.Tuple(elts=[1, 2, 3])),
                _ast.Assign(lineno=2, value=_ast.Str(s='a')),
            ],
        )
    except (AttributeError):
        constructor_with_immutable = _ast.FunctionDef(
            name='__init__',
            body=[
                _ast.Assign(lineno=1, value=_ast.Tuple(elts=[1, 2, 3])),
                _ast.Assign(lineno=3, value=_ast.JoinedStr(values=None)),
            ],
        )
    constructor_with_mutable = _ast.FunctionDef(
        name='__init__',
        body=[
            _ast.Assign(lineno=1, value=_ast.List(elts=[1, 2, 3])),
            _ast.Assign(lineno=2, value=_ast.Set(elts=[1, 2, 3])),
            _ast.Assign(lineno=3, value=_ast.Dict(keys=['a'])),
        ],
    )
Example #2
0
def Set(*items):
    """Creates an _ast.Set node.

  Args:
    *items: The items in the set.

  Returns:
    An _ast.Set node.
  """
    return _ast.Set(elts=list(items))
    def BUILD_SET(self, instr):

        nitems = instr.oparg

        nodes = []
        list_ = _ast.Set(elts=nodes, ctx=_ast.Load(), lineno=instr.lineno, col_offset=0)
        for i in range(nitems):
            nodes.insert(0, self.ast_stack.pop())

        self.ast_stack.append(list_)
Example #4
0
 def test_empty_set(self):
     import ast
     m = ast.Module(body=[ast.Expr(value=ast.Set(elts=[]))])
     ast.fix_missing_locations(m)
     compile(m, "<test>", "exec")