|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +The :mod:`ast` module contains the classes comprising the Python abstract syntax tree. |
| 5 | +
|
| 6 | +Every node class is inherited from the corresponding Python :mod:`..ast` class, |
| 7 | +if one exists in the version of Python that is running. |
| 8 | +
|
| 9 | +All attributes ending with ``loc`` contain instances of :class:`.source.Range` |
| 10 | +or None. All attributes ending with ``_locs`` contain lists of instances of |
| 11 | +:class:`.source.Range` or []. |
| 12 | +""" |
| 13 | + |
| 14 | +from __future__ import absolute_import, division, print_function, unicode_literals |
| 15 | +from .shim import ast |
| 16 | + |
| 17 | +class commonloc(object): |
| 18 | + """ |
| 19 | + A mixin common for all nodes. |
| 20 | +
|
| 21 | + :cvar _fields: (tuple of strings) (defined in Python) |
| 22 | + names of all attributes with semantic values |
| 23 | + :cvar _locs: (tuple of strings) |
| 24 | + names of all attributes with location values |
| 25 | +
|
| 26 | + :ivar loc: range encompassing all locations defined for this node |
| 27 | + or its children |
| 28 | + """ |
| 29 | + |
| 30 | + _locs = ('loc',) |
| 31 | + |
| 32 | + def __repr__(self): |
| 33 | + def value(name): |
| 34 | + try: |
| 35 | + loc = self.__dict__[name] |
| 36 | + if isinstance(loc, list): |
| 37 | + return "[%s]" % (', '.join(map(repr, loc))) |
| 38 | + else: |
| 39 | + return repr(loc) |
| 40 | + except: |
| 41 | + return "(!!!MISSING!!!)" |
| 42 | + fields = ', '.join(map(lambda name: "%s=%s" % (name, value(name)), |
| 43 | + self._fields + self._locs)) |
| 44 | + return "%s(%s)" % (self.__class__.__name__, fields) |
| 45 | + |
| 46 | +class keywordloc(commonloc): |
| 47 | + """ |
| 48 | + A mixin common for all keyword statements, e.g. ``pass`` and ``yield expr``. |
| 49 | +
|
| 50 | + :ivar keyword_loc: location of the keyword, e.g. ``yield``. |
| 51 | + """ |
| 52 | + _locs = commonloc._locs + ('keyword_loc',) |
| 53 | + |
| 54 | +class beginendloc(commonloc): |
| 55 | + """ |
| 56 | + A mixin common for nodes with a opening and closing delimiters, e.g. tuples and lists. |
| 57 | +
|
| 58 | + :ivar begin_loc: location of the opening delimiter, e.g. ``(``. |
| 59 | + :ivar end_loc: location of the closing delimiter, e.g. ``)``. |
| 60 | + """ |
| 61 | + _locs = commonloc._locs + ('begin_loc', 'end_loc') |
| 62 | + |
| 63 | +class alias(commonloc): |
| 64 | + """ |
| 65 | + An import alias, e.g. ``x as y``. |
| 66 | +
|
| 67 | + :ivar name: (string) value to import |
| 68 | + :ivar asname: (string) name to add to the environment |
| 69 | + :ivar as_loc: location of ``as`` |
| 70 | + """ |
| 71 | + _locs = commonloc._locs + ('as_loc',) |
| 72 | + |
| 73 | +class arguments(commonloc): |
| 74 | + """ |
| 75 | + Function definition arguments, e.g. in ``def f(x, y=1, *z, **t)``. |
| 76 | +
|
| 77 | + :ivar args: (list of assignable node) regular formal arguments |
| 78 | + :ivar vararg: (node) splat formal argument (if any), e.g. in ``*x`` |
| 79 | + :ivar kwarg: (node) keyword splat formal argument (if any), e.g. in ``**x`` |
| 80 | + :ivar defaults: (node) values of default arguments |
| 81 | + :ivar star_loc: location of ``*``, if any |
| 82 | + :ivar dstar_loc: location of ``**``, if any |
| 83 | + :ivar default_equals_locs: locations of ``=`` |
| 84 | + """ |
| 85 | + |
| 86 | +class boolop(commonloc): |
| 87 | + """Base class for binary boolean operators.""" |
| 88 | +class And(boolop, ast.And): |
| 89 | + """The ``and`` operator.""" |
| 90 | +class Or(boolop, ast.Or): |
| 91 | + """The ``or`` operator.""" |
| 92 | + |
| 93 | +class cmpop(commonloc): |
| 94 | + """Base class for comparison operators.""" |
| 95 | +class Eq(cmpop, ast.Eq): |
| 96 | + """The ``==`` operator.""" |
| 97 | +class Gt(cmpop, ast.Gt): |
| 98 | + """The ``>`` operator.""" |
| 99 | +class GtE(cmpop, ast.GtE): |
| 100 | + """The ``>=`` operator.""" |
| 101 | +class In(cmpop, ast.In): |
| 102 | + """The ``in`` operator.""" |
| 103 | +class Is(cmpop, ast.Is): |
| 104 | + """The ``is`` operator.""" |
| 105 | +class IsNot(cmpop, ast.IsNot): |
| 106 | + """The ``is not`` operator.""" |
| 107 | +class Lt(cmpop, ast.Lt): |
| 108 | + """The ``<`` operator.""" |
| 109 | +class LtE(cmpop, ast.LtE): |
| 110 | + """The ``<=`` operator.""" |
| 111 | +class NotEq(cmpop, ast.NotEq): |
| 112 | + """The ``!=`` (or deprecated ``<>``) operator.""" |
| 113 | +class NotIn(cmpop, ast.NotIn): |
| 114 | + """The ``not in`` operator.""" |
| 115 | + |
| 116 | +class comprehension(commonloc, ast.comprehension): |
| 117 | + """ |
| 118 | + A single ``for`` list comprehension clause. |
| 119 | +
|
| 120 | + :ivar target: (node) the variable(s) bound in comprehension body |
| 121 | + :ivar iter: (node) the expression being iterated |
| 122 | + :ivar ifs: (list of node) the ``if`` clauses |
| 123 | + :ivar for_loc: location of the ``for`` keyword |
| 124 | + :ivar in_loc: location of the ``in`` keyword |
| 125 | + :ivar if_locs: locations of ``if`` keywords |
| 126 | + """ |
| 127 | + _locs = commonloc._locs + ('for_loc', 'in_loc', 'if_locs') |
| 128 | + |
| 129 | +class excepthandler(commonloc): |
| 130 | + """Base class for the exception handler.""" |
| 131 | +class ExceptHandler(excepthandler, ast.ExceptHandler): |
| 132 | + """ |
| 133 | + An exception handler, e.g. ``except x as y:· z``. |
| 134 | +
|
| 135 | + :ivar type: (node) type of handled exception |
| 136 | + :ivar name: (assignable node) variable bound to exception, if any |
| 137 | + :ivar body: (list of node) code to execute when exception is caught |
| 138 | + :ivar except_loc: location of ``except`` |
| 139 | + :ivar as_loc: location of ``as``, if any |
| 140 | + """ |
| 141 | + _locs = excepthandler._locs + ('except_loc', 'as_loc') |
| 142 | + |
| 143 | +class expr(commonloc): |
| 144 | + """Base class for expression nodes.""" |
| 145 | +class Attribute(expr, ast.Attribute): |
| 146 | + """ |
| 147 | + An attribute access, e.g. ``x.y``. |
| 148 | +
|
| 149 | + :ivar value: (node) left-hand side |
| 150 | + :ivar attr: (string) attribute name |
| 151 | + """ |
| 152 | +class BinOp(expr, ast.BinOp): |
| 153 | + """ |
| 154 | + A binary operation, e.g. ``x + y``. |
| 155 | +
|
| 156 | + :ivar left: (node) left-hand side |
| 157 | + :ivar op: (:class:`operator`) operator |
| 158 | + :ivar right: (node) right-hand side |
| 159 | + """ |
| 160 | +class BoolOp(expr, ast.BoolOp): |
| 161 | + """ |
| 162 | + A boolean operation, e.g. ``x and y``. |
| 163 | +
|
| 164 | + :ivar left: (node) left-hand side |
| 165 | + :ivar op: (:class:`boolop`) operator |
| 166 | + :ivar right: (node) right-hand side |
| 167 | + """ |
| 168 | +class Call(beginendloc, expr, ast.Call): |
| 169 | + """ |
| 170 | + A function call, e.g. ``f(x, y=1, *z, **t)``. |
| 171 | +
|
| 172 | + :ivar func: (node) function to call |
| 173 | + :ivar args: (list of node) regular arguments |
| 174 | + :ivar keywords: (list of :class:`keyword`) keyword arguments |
| 175 | + :ivar starargs: (node) splat argument (if any), e.g. in ``*x`` |
| 176 | + :ivar kwargs: (node) keyword splat argument (if any), e.g. in ``**x`` |
| 177 | + :ivar star_loc: location of ``*``, if any |
| 178 | + :ivar dstar_loc: location of ``**``, if any |
| 179 | + """ |
| 180 | + _locs = beginendloc._locs + ('star_loc', 'dstar_loc') |
| 181 | +class Compare(expr, ast.Compare): |
| 182 | + """ |
| 183 | + A comparison operation, e.g. ``x < y`` or ``x < y > z``. |
| 184 | +
|
| 185 | + :ivar left: (node) left-hand |
| 186 | + :ivar ops: (list of :class:`cmpop`) compare operators |
| 187 | + :ivar comparators: (list of node) compare values |
| 188 | + """ |
| 189 | +class Dict(beginendloc, expr, ast.Dict): |
| 190 | + """ |
| 191 | + A dictionary, e.g. ``{x: y}``. |
| 192 | +
|
| 193 | + :ivar keys: (list of node) keys |
| 194 | + :ivar values: (list of node) values |
| 195 | + :ivar colon_locs: ``:`` locations |
| 196 | + """ |
| 197 | + _locs = beginendloc._locs + ('colon_locs',) |
| 198 | +class DictComp(beginendloc, expr, ast.DictComp): |
| 199 | + """ |
| 200 | + A list comprehension, e.g. ``{x: y for x,y in z}``. |
| 201 | +
|
| 202 | + :ivar key: (node) key part of comprehension body |
| 203 | + :ivar value: (node) value part of comprehension body |
| 204 | + :ivar generators: (list of :class:`comprehension`) ``for`` clauses |
| 205 | + """ |
| 206 | +class GeneratorExp(beginendloc, expr, ast.GeneratorExp): |
| 207 | + """ |
| 208 | + A generator expression, e.g. ``(x for x in y)``. |
| 209 | +
|
| 210 | + :ivar elt: (node) expression body |
| 211 | + :ivar generators: (list of :class:`comprehension`) ``for`` clauses |
| 212 | + """ |
| 213 | +class IfExp(expr, ast.IfExp): |
| 214 | + """ |
| 215 | + A conditional expression, e.g. ``x if y else z``. |
| 216 | +
|
| 217 | + :ivar test: (node) condition |
| 218 | + :ivar body: (node) value if true |
| 219 | + :ivar orelse: (node) value if false |
| 220 | + :ivar if_loc: location of ``if`` |
| 221 | + :ivar else_loc: location of ``else`` |
| 222 | + """ |
| 223 | + _locs = expr._locs + ('if_loc', 'else_loc') |
| 224 | +class Lambda(expr, ast.Lambda): |
| 225 | + """ |
| 226 | + A lambda expression, e.g. ``lambda x: x*x``. |
| 227 | +
|
| 228 | + :ivar args: (:class:`arguments`) arguments |
| 229 | + :ivar body: (node) body |
| 230 | + :ivar keyword_loc: location of ``lambda`` |
| 231 | + :ivar colon_loc: location of ``:`` |
| 232 | + """ |
| 233 | + _locs = expr._locs + ('keyword_loc', 'colon_loc') |
| 234 | +class List(beginendloc, expr, ast.List): |
| 235 | + """ |
| 236 | + A list, e.g. ``[x, y]``. |
| 237 | +
|
| 238 | + :ivar elts: (list of node) elements |
| 239 | + """ |
| 240 | +class ListComp(beginendloc, expr, ast.ListComp): |
| 241 | + """ |
| 242 | + A list comprehension, e.g. ``[x for x in y]``. |
| 243 | +
|
| 244 | + :ivar elt: (node) comprehension body |
| 245 | + :ivar generators: (list of :class:`comprehension`) ``for`` clauses |
| 246 | + """ |
| 247 | +class Name(expr, ast.Name): |
| 248 | + """ |
| 249 | + An identifier, e.g. ``x``. |
| 250 | +
|
| 251 | + :ivar id: (string) name |
| 252 | + """ |
| 253 | +class Num(expr, ast.Num): |
| 254 | + """ |
| 255 | + An integer, floating point or complex number, e.g. ``1``, ``1.0`` or ``1.0j``. |
| 256 | +
|
| 257 | + :ivar n: (int, float or complex) value |
| 258 | + """ |
| 259 | +class Repr(beginendloc, expr, ast.Repr): |
| 260 | + """ |
| 261 | + A repr operation, e.g. ``\`x\``` |
| 262 | +
|
| 263 | + :ivar value: (node) value |
| 264 | + """ |
| 265 | +class Set(beginendloc, expr, ast.Set): |
| 266 | + """ |
| 267 | + A set, e.g. ``{x, y}``. |
| 268 | +
|
| 269 | + :ivar elts: (list of node) elements |
| 270 | + """ |
| 271 | +class SetComp(beginendloc, expr, ast.ListComp): |
| 272 | + """ |
| 273 | + A set comprehension, e.g. ``{x for x in y}``. |
| 274 | +
|
| 275 | + :ivar elt: (node) comprehension body |
| 276 | + :ivar generators: (list of :class:`comprehension`) ``for`` clauses |
| 277 | + """ |
| 278 | +class Str(beginendloc, expr, ast.Str): |
| 279 | + """ |
| 280 | + A string, e.g. ``"x"``. |
| 281 | +
|
| 282 | + :ivar s: (string) value |
| 283 | + """ |
| 284 | +class Subscript(beginendloc, expr, ast.Subscript): |
| 285 | + """ |
| 286 | + A subscript operation, e.g. ``x[1]``. |
| 287 | +
|
| 288 | + :ivar value: (node) object being sliced |
| 289 | + :ivar slice: (:class:`slice`) slice |
| 290 | + """ |
| 291 | +class Tuple(beginendloc, expr, ast.Tuple): |
| 292 | + """ |
| 293 | + A tuple, e.g. ``(x,)`` or ``x,y``. |
| 294 | +
|
| 295 | + :ivar elts: (list of nodes) elements |
| 296 | + """ |
| 297 | +class UnaryOp(expr, ast.UnaryOp): |
| 298 | + """ |
| 299 | + An unary operation, e.g. ``+x``. |
| 300 | +
|
| 301 | + :ivar op: (:class:`unaryop`) operator |
| 302 | + :ivar operand: (node) operand |
| 303 | + """ |
| 304 | +class Yield(expr, ast.Yield): |
| 305 | + """ |
| 306 | + A yield expression, e.g. ``yield x``. |
| 307 | +
|
| 308 | + :ivar value: (node) yielded value |
| 309 | + """ |
| 310 | + |
| 311 | +# expr_context |
| 312 | +# AugLoad |
| 313 | +# AugStore |
| 314 | +# Del |
| 315 | +# Load |
| 316 | +# Param |
| 317 | +# Store |
| 318 | + |
| 319 | +class keyword(commonloc, ast.keyword): |
| 320 | + """ |
| 321 | + A keyword actual argument, e.g. in ``f(x=1)``. |
| 322 | +
|
| 323 | + :ivar arg: (string) name |
| 324 | + :ivar value: (node) value |
| 325 | + :ivar equals_loc: location of ``=`` |
| 326 | + """ |
| 327 | + _locs = commonloc._locs + ('equals_loc',) |
| 328 | + |
| 329 | +class mod(commonloc): |
| 330 | + """Base class for modules (groups of statements).""" |
| 331 | + _locs = commonloc._locs + ('body',) |
| 332 | +class Expression(mod, ast.Expression): |
| 333 | + """A group of statements parsed as if for :func:`eval`.""" |
| 334 | +class Interactive(mod, ast.Interactive): |
| 335 | + """A group of statements parsed as if it was REPL input.""" |
| 336 | +class Module(mod, ast.Module): |
| 337 | + """A group of statements parsed as if it was a file.""" |
| 338 | +class Suite(mod, ast.Suite): |
| 339 | + """ |
| 340 | + Doesn't appear to be used by Python; included for compatibility |
| 341 | + with :mod:`ast`. |
| 342 | + """ |
| 343 | + |
| 344 | +class operator(commonloc): |
| 345 | + """Base class for numeric binary operators.""" |
| 346 | +class Add(operator, ast.Add): |
| 347 | + """The ``+`` operator.""" |
| 348 | +class BitAnd(operator, ast.BitAnd): |
| 349 | + """The ``&`` operator.""" |
| 350 | +class BitOr(operator, ast.BitOr): |
| 351 | + """The ``|`` operator.""" |
| 352 | +class BitXor(operator, ast.BitXor): |
| 353 | + """The ``^`` operator.""" |
| 354 | +class Div(operator, ast.Div): |
| 355 | + """The ``\\`` operator.""" |
| 356 | +class FloorDiv(operator, ast.FloorDiv): |
| 357 | + """The ``\\\\`` operator.""" |
| 358 | +class LShift(operator, ast.LShift): |
| 359 | + """The ``<<`` operator.""" |
| 360 | +class Mod(operator, ast.Mod): |
| 361 | + """The ``%`` operator.""" |
| 362 | +class Mult(operator, ast.Mult): |
| 363 | + """The ``*`` operator.""" |
| 364 | +class Pow(operator, ast.Pow): |
| 365 | + """The ``**`` operator.""" |
| 366 | +class RShift(operator, ast.RShift): |
| 367 | + """The ``>>`` operator.""" |
| 368 | +class Sub(operator, ast.Sub): |
| 369 | + """The ``-`` operator.""" |
| 370 | + |
| 371 | +class slice(commonloc): |
| 372 | + """Base class for slice operations.""" |
| 373 | +class Ellipsis(slice, ast.Ellipsis): |
| 374 | + """The ellipsis, e.g. in ``x[...]``.""" |
| 375 | +class ExtSlice(slice, ast.ExtSlice): |
| 376 | + """ |
| 377 | + The multiple slice, e.g. in ``x[0:1, 2:3]``. |
| 378 | +
|
| 379 | + :ivar dims: (:class:`slice`) sub-slices |
| 380 | + """ |
| 381 | +class Index(slice, ast.Index): |
| 382 | + """ |
| 383 | + The index, e.g. in ``x[1]``. |
| 384 | +
|
| 385 | + :ivar value: (node) index |
| 386 | + """ |
| 387 | +class Slice(slice, ast.Slice): |
| 388 | + """ |
| 389 | + The slice, e.g. in ``x[0:1]`` or ``x[0:1:2]``. |
| 390 | +
|
| 391 | + :ivar lower: (node or None) lower bound |
| 392 | + :ivar upper: (node or None) upper bound |
| 393 | + :ivar step: (node or None) iteration step |
| 394 | + :ivar bound_colon_loc: location of first semicolon |
| 395 | + :ivar step_colon_loc: location of second semicolon |
| 396 | + """ |
| 397 | + _locs = slice._locs + ('bound_colon_loc', 'step_colon_loc') |
| 398 | + |
| 399 | +class stmt(commonloc): |
| 400 | + """Base class for statement nodes.""" |
| 401 | +class Assert(keywordloc, stmt, ast.Assert): |
| 402 | + """ |
| 403 | + The ``assert x, msg`` statement. |
| 404 | +
|
| 405 | + :ivar test: (node) condition |
| 406 | + :ivar msg: (node) message, if any |
| 407 | + """ |
| 408 | +class Assign(stmt, ast.Assign): |
| 409 | + """ |
| 410 | + The ``=`` statement. |
| 411 | +
|
| 412 | + :ivar targets: (list of assignable node) left-hand sides |
| 413 | + :ivar value: (node) right-hand side |
| 414 | + :ivar ops_loc: location of equality signs corresponding to ``targets`` |
| 415 | + """ |
| 416 | +class AugAssign(stmt, ast.AugAssign): |
| 417 | + """ |
| 418 | + The operator-assignment statement, e.g. ``+=``. |
| 419 | +
|
| 420 | + :ivar target: (assignable node) left-hand side |
| 421 | + :ivar op: (:class:`ast.operator`) operator |
| 422 | + :ivar value: (node) right-hand side |
| 423 | + """ |
| 424 | +class Break(keywordloc, stmt, ast.Break): |
| 425 | + """The ``break`` statement.""" |
| 426 | +class ClassDef(keywordloc, stmt, ast.ClassDef): |
| 427 | + """ |
| 428 | + The ``class x(y, z):· t`` statement. |
| 429 | +
|
| 430 | + :ivar name: (string) name |
| 431 | + :ivar bases: (list of node) base classes |
| 432 | + :ivar body: (list of node) body |
| 433 | + :ivar decorator_list: (list of node) decorators |
| 434 | + :ivar keyword_loc: location of ``class`` |
| 435 | + :ivar name_loc: location of name |
| 436 | + :ivar lparen_loc: location of ``(``, if any |
| 437 | + :ivar rparen_loc: location of ``)``, if any |
| 438 | + """ |
| 439 | + _locs = keywordloc._locs + ('name_loc', 'lparen_loc', 'rparen_loc') |
| 440 | +class Continue(keywordloc, stmt, ast.Continue): |
| 441 | + """The ``continue`` statement.""" |
| 442 | +class Delete(keywordloc, stmt, ast.Delete): |
| 443 | + """ |
| 444 | + The ``del x, y`` statement. |
| 445 | +
|
| 446 | + :ivar targets: (list of :class:`Name`) |
| 447 | + """ |
| 448 | +class Exec(keywordloc, stmt, ast.Exec): |
| 449 | + """ |
| 450 | + The ``exec code in locals, globals`` statement. |
| 451 | +
|
| 452 | + :ivar body: (node) code |
| 453 | + :ivar locals: (node) locals |
| 454 | + :ivar globals: (node) globals |
| 455 | + :ivar keyword_loc: location of ``exec`` |
| 456 | + :ivar in_loc: location of ``in`` |
| 457 | + """ |
| 458 | + _locs = keywordloc._locs + ('in_loc',) |
| 459 | +class Expr(stmt, ast.Expr): |
| 460 | + """ |
| 461 | + An expression in statement context. The value of expression is discarded. |
| 462 | +
|
| 463 | + :ivar value: (:class:`expr`) value |
| 464 | + """ |
| 465 | +class For(keywordloc, stmt, ast.While): |
| 466 | + """ |
| 467 | + The ``for x in y:· z·else:· t`` statement. |
| 468 | +
|
| 469 | + :ivar target: (assignable node) loop variable |
| 470 | + :ivar iter: (node) loop collection |
| 471 | + :ivar body: (list of node) code for every iteration |
| 472 | + :ivar orelse: (list of node) code if empty |
| 473 | + :ivar keyword_loc: location of ``for`` |
| 474 | + :ivar in_loc: location of ``in`` |
| 475 | + :ivar for_colon_loc: location of colon after ``for`` |
| 476 | + :ivar else_loc: location of ``else``, if any |
| 477 | + :ivar else_colon_loc: location of colon after ``else``, if any |
| 478 | + """ |
| 479 | + _locs = keywordloc._locs + ('in_loc', 'for_colon_loc', 'else_loc', 'else_colon_loc') |
| 480 | +class FunctionDef(keywordloc, stmt, ast.FunctionDef): |
| 481 | + """ |
| 482 | + The ``def f(x):· y`` statement. |
| 483 | +
|
| 484 | + :ivar name: (string) name |
| 485 | + :ivar args: (:class:`arguments`) formal arguments |
| 486 | + :ivar body: (list of node) body |
| 487 | + :ivar keyword_loc: location of ``def`` |
| 488 | + :ivar decorator_list: (list of node) decorators |
| 489 | + :ivar name_loc: location of name |
| 490 | + :ivar colon_loc: location of ``:``, if any |
| 491 | + """ |
| 492 | + _locs = keywordloc._locs + ('keyword_loc' 'name_loc', 'colon_loc') |
| 493 | +class Global(keywordloc, stmt, ast.Global): |
| 494 | + """ |
| 495 | + The ``global x, y`` statement. |
| 496 | +
|
| 497 | + :ivar names: (list of :class:`Name`) names |
| 498 | + """ |
| 499 | +class If(keywordloc, stmt, ast.If): |
| 500 | + """ |
| 501 | + The ``if x:· y·else:· z`` or ``if x:· y·elif: z· t`` statement. |
| 502 | +
|
| 503 | + :ivar test: (node) condition |
| 504 | + :ivar body: (list of node) code if true |
| 505 | + :ivar orelse: (list of node) code if false |
| 506 | + :ivar if_colon_loc: location of colon after ``if`` or ``elif`` |
| 507 | + :ivar else_loc: location of ``else``, if any |
| 508 | + :ivar else_colon_loc: location of colon after ``else``, if any |
| 509 | + """ |
| 510 | + _locs = keywordloc._locs + ('if_colon_loc', 'else_loc', 'else_colon_loc') |
| 511 | +class Import(keywordloc, stmt, ast.Import): |
| 512 | + """ |
| 513 | + The ``import x, y`` statement. |
| 514 | +
|
| 515 | + :ivar names: (list of :class:`alias`) names |
| 516 | + """ |
| 517 | +class ImportFrom(keywordloc, stmt, ast.Import): |
| 518 | + """ |
| 519 | + The ``from ...x import y, z`` statement. |
| 520 | +
|
| 521 | + :ivar names: (list of :class:`alias`) names |
| 522 | + :ivar module: (string) module name |
| 523 | + :ivar level: (integer) amount of dots before module name |
| 524 | + :ivar keyword_loc: location of ``from`` |
| 525 | + :ivar dots_loc: location of dots |
| 526 | + :ivar module_loc: location of module name |
| 527 | + :ivar import_loc: location of ``import`` |
| 528 | + """ |
| 529 | + _locs = keywordloc._locs + ('dots_loc', 'module_loc', 'import_loc') |
| 530 | +class Pass(keywordloc, stmt, ast.Pass): |
| 531 | + """The ``pass`` statement.""" |
| 532 | +class Print(keywordloc, stmt, ast.Print): |
| 533 | + """ |
| 534 | + The ``print >>x, y, z,`` statement. |
| 535 | +
|
| 536 | + :ivar dest: (node) destination stream, if any |
| 537 | + :ivar values: (list of node) values to print |
| 538 | + :ivar nl: (boolean) whether to print newline after values |
| 539 | + :ivar dest_loc: location of ``>>`` |
| 540 | + """ |
| 541 | + _locs = keywordloc._locs + ('dest_loc',) |
| 542 | +class Raise(keywordloc, stmt, ast.Raise): |
| 543 | + """ |
| 544 | + The ``raise exn, arg, traceback`` statement. |
| 545 | +
|
| 546 | + :ivar type: (node) exception type or instance |
| 547 | + :ivar inst: (node) exception instance or argument list, if any |
| 548 | + :ivar tback: (node) traceback, if any |
| 549 | + """ |
| 550 | +class Return(keywordloc, stmt, ast.Return): |
| 551 | + """The ``return x`` statement.""" |
| 552 | +class TryExcept(keywordloc, stmt, ast.TryExcept): |
| 553 | + """ |
| 554 | + The ``try:· x·except y:· z·else:· t`` statement. |
| 555 | +
|
| 556 | + :ivar body: (list of node) code to try |
| 557 | + :ivar handlers: |
| 558 | + :ivar orelse: (list of node) code if no exception |
| 559 | + :ivar keyword_loc: location of ``try`` |
| 560 | + :ivar try_colon_loc: location of ``:`` after ``try`` |
| 561 | + :ivar else_loc: location of ``else`` |
| 562 | + :ivar else_colon_loc: location of ``:`` after ``else`` |
| 563 | + """ |
| 564 | + _locs = keywordloc._locs + ('try_colon_loc', 'else_loc', 'else_colon_loc',) |
| 565 | +class TryFinally(keywordloc, stmt, ast.TryExcept): |
| 566 | + """ |
| 567 | + The ``try:· x·finally:· y`` statement. |
| 568 | +
|
| 569 | + :ivar body: (list of node) code to try |
| 570 | + :ivar finalbody: (list of node) code to finalize |
| 571 | + :ivar keyword_loc: location of ``try`` |
| 572 | + :ivar try_colon_loc: location of ``:`` after ``try`` |
| 573 | + :ivar finally_loc: location of ``finally`` |
| 574 | + :ivar finally_colon_loc: location of ``:`` after ``finally`` |
| 575 | + """ |
| 576 | + _locs = keywordloc._locs + ('try_colon_loc', 'finally_loc', 'finally_colon_loc',) |
| 577 | +class While(keywordloc, stmt, ast.While): |
| 578 | + """ |
| 579 | + The ``while x:· y·else:· z`` statement. |
| 580 | +
|
| 581 | + :ivar test: (node) condition |
| 582 | + :ivar body: (list of node) code for every iteration |
| 583 | + :ivar orelse: (list of node) code if empty |
| 584 | + :ivar keyword_loc: location of ``while`` |
| 585 | + :ivar while_colon_loc: location of colon after ``while`` |
| 586 | + :ivar else_loc: location of ``else``, if any |
| 587 | + :ivar else_colon_loc: location of colon after ``else``, if any |
| 588 | + """ |
| 589 | + _locs = keywordloc._locs + ('while_loc', 'while_colon_loc', 'else_loc', 'else_colon_loc') |
| 590 | +class With(keywordloc, stmt, ast.With): |
| 591 | + """ |
| 592 | + The ``with x as y:· z`` statement. |
| 593 | +
|
| 594 | + :ivar context_expr: (node) context |
| 595 | + :ivar optional_vars: (assignable node) context binding |
| 596 | + :ivar body: (node) body |
| 597 | + :ivar keyword_loc: location of ``with`` |
| 598 | + :ivar as_loc: location of ``as``, if any |
| 599 | + :ivar colon_loc: location of ``:`` |
| 600 | + """ |
| 601 | + _locs = keywordloc._locs + ('colon_loc',) |
| 602 | + |
| 603 | +class unaryop(commonloc): |
| 604 | + """Base class for unary numeric and boolean operators.""" |
| 605 | +class Invert(unaryop, ast.Invert): |
| 606 | + """The ``~`` operator.""" |
| 607 | +class Not(unaryop, ast.Not): |
| 608 | + """The ``not`` operator.""" |
| 609 | +class UAdd(unaryop, ast.UAdd): |
| 610 | + """The unary ``+`` operator.""" |
| 611 | +class USub(unaryop, ast.USub): |
| 612 | + """The unary ``-`` operator.""" |
0 commit comments