Back to index

python3.2  3.2.2
Classes | Functions
lib2to3.fixes.fix_tuple_params Namespace Reference

Classes

class  FixTupleParams

Functions

def is_docstring
def simplify_args
def find_params
def map_to_index
def tuple_name

Detailed Description

Fixer for function definitions with tuple parameters.

def func(((a, b), c), d):
    ...

    ->

def func(x, d):
    ((a, b), c) = x
    ...

It will also support lambdas:

    lambda (x, y): x + y -> lambda t: t[0] + t[1]

    # The parens are a syntax error in Python 3
    lambda (x): x + y -> lambda x: x + y

Function Documentation

Definition at line 150 of file fix_tuple_params.py.

00150 
00151 def find_params(node):
00152     if node.type == syms.vfpdef:
00153         return find_params(node.children[1])
00154     elif node.type == token.NAME:
00155         return node.value
00156     return [find_params(c) for c in node.children if c.type != token.COMMA]

Here is the caller graph for this function:

Definition at line 27 of file fix_tuple_params.py.

00027 
00028 def is_docstring(stmt):
00029     return isinstance(stmt, pytree.Node) and \
00030            stmt.children[0].type == token.STRING

Here is the caller graph for this function:

def lib2to3.fixes.fix_tuple_params.map_to_index (   param_list,
  prefix = [],
  d = None 
)

Definition at line 157 of file fix_tuple_params.py.

00157 
00158 def map_to_index(param_list, prefix=[], d=None):
00159     if d is None:
00160         d = {}
00161     for i, obj in enumerate(param_list):
00162         trailer = [Subscript(Number(str(i)))]
00163         if isinstance(obj, list):
00164             map_to_index(obj, trailer, d=d)
00165         else:
00166             d[obj] = prefix + trailer
00167     return d

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 139 of file fix_tuple_params.py.

00139 
00140 def simplify_args(node):
00141     if node.type in (syms.vfplist, token.NAME):
00142         return node
00143     elif node.type == syms.vfpdef:
00144         # These look like vfpdef< '(' x ')' > where x is NAME
00145         # or another vfpdef instance (leading to recursion).
00146         while node.type == syms.vfpdef:
00147             node = node.children[1]
00148         return node
00149     raise RuntimeError("Received unexpected node %s" % node)

Here is the caller graph for this function:

Definition at line 168 of file fix_tuple_params.py.

00168 
00169 def tuple_name(param_list):
00170     l = []
00171     for obj in param_list:
00172         if isinstance(obj, list):
00173             l.append(tuple_name(obj))
00174         else:
00175             l.append(obj)
00176     return "_".join(l)

Here is the caller graph for this function: