Changeset 388 for python/vendor/current/Lib/ast.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/ast.py
r2 r388 30 30 31 31 32 def parse( expr, filename='<unknown>', mode='exec'):33 """ 34 Parse an expressioninto an AST node.35 Equivalent to compile( expr, filename, mode, PyCF_ONLY_AST).36 """ 37 return compile( expr, filename, mode, PyCF_ONLY_AST)32 def parse(source, filename='<unknown>', mode='exec'): 33 """ 34 Parse the source into an AST node. 35 Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). 36 """ 37 return compile(source, filename, mode, PyCF_ONLY_AST) 38 38 39 39 … … 65 65 if node.id in _safe_names: 66 66 return _safe_names[node.id] 67 elif isinstance(node, BinOp) and \ 68 isinstance(node.op, (Add, Sub)) and \ 69 isinstance(node.right, Num) and \ 70 isinstance(node.right.n, complex) and \ 71 isinstance(node.left, Num) and \ 72 isinstance(node.left.n, (int, long, float)): 73 left = node.left.n 74 right = node.right.n 75 if isinstance(node.op, Add): 76 return left + right 77 else: 78 return left - right 67 79 raise ValueError('malformed string') 68 80 return _convert(node_or_string) … … 141 153 This is useful to "move code" to a different location in a file. 142 154 """ 143 if 'lineno' in node._attributes:144 node.lineno = getattr(node, 'lineno', 0) + n145 155 for child in walk(node): 146 156 if 'lineno' in child._attributes: … … 193 203 def walk(node): 194 204 """ 195 Recursively yield all child nodes of *node*, in no specified order. This is196 useful if you only want to modify nodes in place and don't care about the197 context.205 Recursively yield all descendant nodes in the tree starting at *node* 206 (including *node* itself), in no specified order. This is useful if you 207 only want to modify nodes in place and don't care about the context. 198 208 """ 199 209 from collections import deque
Note:
See TracChangeset
for help on using the changeset viewer.