Skip to content

Commit d3396d5

Browse files
author
whitequark
committedMay 10, 2015
Documentation fixes.
1 parent 6345181 commit d3396d5

File tree

4 files changed

+131
-97
lines changed

4 files changed

+131
-97
lines changed
 

‎doc/index.rst

+31-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ It parses source code into an AST that is a superset of Python's
66
built-in :mod:`ast` module, but returns precise location information
77
for every token.
88

9+
The most useful APIs of PyParser are :meth:`pyparser.parse`,
10+
which parses the source, :mod:`pyparser.ast`, which provides access
11+
to the semantic and location information in the AST, and
12+
:mod:`pyparser.diagnostic.Engine`, which provides a unified way
13+
to report errors and warnings both to PyParser itself and to any
14+
code that consumes the ASTs. The :class:`pyparser.source.Range` class,
15+
instances of which are contained in the AST, allows to extract
16+
location information in various convenient formats.
17+
18+
TODO: algorithms
19+
20+
If a consumer of ASTs wishes to modify the original source without
21+
losing formatting, it can use :class:`pyparser.source.Rewriter`
22+
to insert code fragments around or instead of a known
23+
:class:`pyparser.source.Range`. If the AST is not expected to
24+
change after the modification, it is recommended to re-parse
25+
the result and compare it to the original AST using <ALGO>.
26+
27+
For some applications, e.g. syntax highlighting,
28+
:class:`pyparser.lexer.Lexer` will be able to provide a raw
29+
stream of tokens.
30+
931
:mod:`pyparser` Module
1032
----------------------
1133

@@ -38,19 +60,23 @@ for every token.
3860

3961
.. automodule:: pyparser.ast
4062
:members: commonloc, beginendloc, keywordloc,
63+
AST,
4164
alias,
65+
arg,
4266
arguments,
4367
boolop, And, Or,
4468
cmpop, Eq, Gt, GtE, In, Is, IsNot, Lt, LtE, NotEq, NotIn,
4569
comprehension,
46-
expr, BinOp, BoolOp, Call, Compare, Dict, DictComp, GeneratorExp, IfExp, Lambda,
70+
excepthandler, ExceptHandler,
71+
expr, BinOp, BoolOp, Call, Compare, Dict, DictComp, Ellipsis, GeneratorExp, IfExp, Lambda,
4772
List, ListComp, Name, Num, Repr, Set, SetComp, Str, Subscript, Tuple, UnaryOp, Yield,
4873
keyword,
4974
mod, Expression, Interactive, Module,
5075
operator, Add, BitAnd, BitOr, BitXor, Div, FloorDiv, LShift, Mod, Mult, Pow, RShift, Sub,
51-
slice, Ellipsis, ExtSlice, Index, Slice,
76+
slice, ExtSlice, Index, Slice,
5277
stmt, Assert, Assign, AugAssign, Break, ClassDef, Continue, Delete, Exec, Expr, For,
53-
FunctionDef, Global, If, Import, ImportFrom, Pass, Print, Raise, Return, TryExcept,
54-
TryFinally, While, With,
55-
unaryop, Invert, Not, UAdd, USub
78+
FunctionDef, Global, If, Import, ImportFrom, Nonlocal, Pass, Print, Raise, Return,
79+
TryExcept, TryFinally, While, With,
80+
unaryop, Invert, Not, UAdd, USub,
81+
withitem
5682
:show-inheritance:

‎pyparser/ast.py

+94-92
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
* :class:`With`: on 2.6-2.7 it uses the 3.0 format.
2020
* :class:`arguments`: on 2.6-3.1 it uses the 3.2 format, with dedicated
21-
:class:`arg` in ``vararg`` and ``kwarg`` slots.
21+
:class:`arg` in ``vararg`` and ``kwarg`` slots.
2222
"""
2323

2424
from __future__ import absolute_import, division, print_function, unicode_literals
@@ -102,7 +102,7 @@ class arg(AST, commonloc):
102102
A formal argument, e.g. in ``def f(x)`` or ``def f(x: T)``.
103103
104104
:ivar arg: (string) argument name
105-
:ivar annotation: (node) type annotation, if any; **emitted since 3.0**
105+
:ivar annotation: (:class:`AST`) type annotation, if any; **emitted since 3.0**
106106
:ivar arg_loc: location of argument name
107107
:ivar colon_loc: location of ``:``, if any; **emitted since 3.0**
108108
"""
@@ -114,11 +114,11 @@ class arguments(AST, beginendloc):
114114
Function definition arguments, e.g. in ``def f(x, y=1, *z, **t)``.
115115
116116
:ivar args: (list of :class:`arg`) regular formal arguments
117-
:ivar defaults: (list of node) values of default arguments
117+
:ivar defaults: (list of :class:`AST`) values of default arguments
118118
:ivar vararg: (:class:`arg`) splat formal argument (if any), e.g. in ``*x``
119-
:ivar kwonlyargs: (list of :class:`arg`) keyword-only (post-*) formal arguments;
119+
:ivar kwonlyargs: (list of :class:`arg`) keyword-only (post-\*) formal arguments;
120120
**emitted since 3.0**
121-
:ivar kw_defaults: (list of node) values of default keyword-only arguments;
121+
:ivar kw_defaults: (list of :class:`AST`) values of default keyword-only arguments;
122122
**emitted since 3.0**
123123
:ivar kwarg: (:class:`arg`) keyword splat formal argument (if any), e.g. in ``**x``
124124
:ivar star_loc: location of ``*``, if any
@@ -171,9 +171,9 @@ class comprehension(AST, commonloc):
171171
"""
172172
A single ``for`` list comprehension clause.
173173
174-
:ivar target: (node) the variable(s) bound in comprehension body
175-
:ivar iter: (node) the expression being iterated
176-
:ivar ifs: (list of node) the ``if`` clauses
174+
:ivar target: (:class:`AST`) the variable(s) bound in comprehension body
175+
:ivar iter: (:class:`AST`) the expression being iterated
176+
:ivar ifs: (list of :class:`AST`) the ``if`` clauses
177177
:ivar for_loc: location of the ``for`` keyword
178178
:ivar in_loc: location of the ``in`` keyword
179179
:ivar if_locs: locations of ``if`` keywords
@@ -187,9 +187,9 @@ class ExceptHandler(excepthandler):
187187
"""
188188
An exception handler, e.g. ``except x as y:· z``.
189189
190-
:ivar type: (node) type of handled exception, if any
191-
:ivar name: (assignable node) variable bound to exception, if any
192-
:ivar body: (list of node) code to execute when exception is caught
190+
:ivar type: (:class:`AST`) type of handled exception, if any
191+
:ivar name: (assignable :class:`AST`) variable bound to exception, if any
192+
:ivar body: (list of :class:`AST`) code to execute when exception is caught
193193
:ivar except_loc: location of ``except``
194194
:ivar as_loc: location of ``as``, if any
195195
:ivar colon_loc: location of ``:``
@@ -203,7 +203,7 @@ class Attribute(expr):
203203
"""
204204
An attribute access, e.g. ``x.y``.
205205
206-
:ivar value: (node) left-hand side
206+
:ivar value: (:class:`AST`) left-hand side
207207
:ivar attr: (string) attribute name
208208
"""
209209
_fields = ('value', 'attr', 'ctx')
@@ -212,17 +212,17 @@ class BinOp(expr):
212212
"""
213213
A binary operation, e.g. ``x + y``.
214214
215-
:ivar left: (node) left-hand side
215+
:ivar left: (:class:`AST`) left-hand side
216216
:ivar op: (:class:`operator`) operator
217-
:ivar right: (node) right-hand side
217+
:ivar right: (:class:`AST`) right-hand side
218218
"""
219219
_fields = ('left', 'op', 'right')
220220
class BoolOp(expr):
221221
"""
222222
A boolean operation, e.g. ``x and y``.
223223
224224
:ivar op: (:class:`boolop`) operator
225-
:ivar values: (list of node) operands
225+
:ivar values: (list of :class:`AST`) operands
226226
:ivar op_locs: locations of operators
227227
"""
228228
_fields = ('op', 'values')
@@ -231,11 +231,11 @@ class Call(expr, beginendloc):
231231
"""
232232
A function call, e.g. ``f(x, y=1, *z, **t)``.
233233
234-
:ivar func: (node) function to call
235-
:ivar args: (list of node) regular arguments
234+
:ivar func: (:class:`AST`) function to call
235+
:ivar args: (list of :class:`AST`) regular arguments
236236
:ivar keywords: (list of :class:`keyword`) keyword arguments
237-
:ivar starargs: (node) splat argument (if any), e.g. in ``*x``
238-
:ivar kwargs: (node) keyword splat argument (if any), e.g. in ``**x``
237+
:ivar starargs: (:class:`AST`) splat argument (if any), e.g. in ``*x``
238+
:ivar kwargs: (:class:`AST`) keyword splat argument (if any), e.g. in ``**x``
239239
:ivar star_loc: location of ``*``, if any
240240
:ivar dstar_loc: location of ``**``, if any
241241
"""
@@ -245,18 +245,18 @@ class Compare(expr):
245245
"""
246246
A comparison operation, e.g. ``x < y`` or ``x < y > z``.
247247
248-
:ivar left: (node) left-hand
248+
:ivar left: (:class:`AST`) left-hand
249249
:ivar ops: (list of :class:`cmpop`) compare operators
250-
:ivar comparators: (list of node) compare values
250+
:ivar comparators: (list of :class:`AST`) compare values
251251
"""
252252
_fields = ('left', 'ops', 'comparators')
253253
class Dict(expr, beginendloc):
254254
"""
255255
A dictionary, e.g. ``{x: y}``.
256256
257-
:ivar keys: (list of node) keys
258-
:ivar values: (list of node) values
259-
:ivar colon_locs: ``:`` locations
257+
:ivar keys: (list of :class:`AST`) keys
258+
:ivar values: (list of :class:`AST`) values
259+
:ivar colon_locs: locations of ``:``
260260
"""
261261
_fields = ('keys', 'values')
262262
_locs = beginendloc._locs + ('colon_locs',)
@@ -266,8 +266,8 @@ class DictComp(expr, beginendloc):
266266
267267
**Emitted since 2.7.**
268268
269-
:ivar key: (node) key part of comprehension body
270-
:ivar value: (node) value part of comprehension body
269+
:ivar key: (:class:`AST`) key part of comprehension body
270+
:ivar value: (:class:`AST`) value part of comprehension body
271271
:ivar generators: (list of :class:`comprehension`) ``for`` clauses
272272
:ivar colon_loc: location of ``:``
273273
"""
@@ -279,17 +279,17 @@ class GeneratorExp(expr, beginendloc):
279279
"""
280280
A generator expression, e.g. ``(x for x in y)``.
281281
282-
:ivar elt: (node) expression body
282+
:ivar elt: (:class:`AST`) expression body
283283
:ivar generators: (list of :class:`comprehension`) ``for`` clauses
284284
"""
285285
_fields = ('elt', 'generators')
286286
class IfExp(expr):
287287
"""
288288
A conditional expression, e.g. ``x if y else z``.
289289
290-
:ivar test: (node) condition
291-
:ivar body: (node) value if true
292-
:ivar orelse: (node) value if false
290+
:ivar test: (:class:`AST`) condition
291+
:ivar body: (:class:`AST`) value if true
292+
:ivar orelse: (:class:`AST`) value if false
293293
:ivar if_loc: location of ``if``
294294
:ivar else_loc: location of ``else``
295295
"""
@@ -300,7 +300,7 @@ class Lambda(expr):
300300
A lambda expression, e.g. ``lambda x: x*x``.
301301
302302
:ivar args: (:class:`arguments`) arguments
303-
:ivar body: (node) body
303+
:ivar body: (:class:`AST`) body
304304
:ivar lambda_loc: location of ``lambda``
305305
:ivar colon_loc: location of ``:``
306306
"""
@@ -310,14 +310,14 @@ class List(expr, beginendloc):
310310
"""
311311
A list, e.g. ``[x, y]``.
312312
313-
:ivar elts: (list of node) elements
313+
:ivar elts: (list of :class:`AST`) elements
314314
"""
315315
_fields = ('elts', 'ctx')
316316
class ListComp(expr, beginendloc):
317317
"""
318318
A list comprehension, e.g. ``[x for x in y]``.
319319
320-
:ivar elt: (node) comprehension body
320+
:ivar elt: (:class:`AST`) comprehension body
321321
:ivar generators: (list of :class:`comprehension`) ``for`` clauses
322322
"""
323323
_fields = ('elt', 'generators')
@@ -348,7 +348,7 @@ class Repr(expr, beginendloc):
348348
349349
**Emitted until 3.0.**
350350
351-
:ivar value: (node) value
351+
:ivar value: (:class:`AST`) value
352352
"""
353353
_fields = ('value',)
354354
class Set(expr, beginendloc):
@@ -357,7 +357,7 @@ class Set(expr, beginendloc):
357357
358358
**Emitted since 2.7.**
359359
360-
:ivar elts: (list of node) elements
360+
:ivar elts: (list of :class:`AST`) elements
361361
"""
362362
_fields = ('elts',)
363363
class SetComp(expr, beginendloc):
@@ -366,7 +366,7 @@ class SetComp(expr, beginendloc):
366366
367367
**Emitted since 2.7.**
368368
369-
:ivar elt: (node) comprehension body
369+
:ivar elt: (:class:`AST`) comprehension body
370370
:ivar generators: (list of :class:`comprehension`) ``for`` clauses
371371
"""
372372
_fields = ('elt', 'generators')
@@ -381,7 +381,7 @@ class Starred(expr):
381381
"""
382382
A starred expression, e.g. ``*x`` in ``*x, y = z``.
383383
384-
:ivar value: (node) expression
384+
:ivar value: (:class:`AST`) expression
385385
:ivar star_loc: location of ``*``
386386
"""
387387
_fields = ('value',)
@@ -390,7 +390,7 @@ class Subscript(expr, beginendloc):
390390
"""
391391
A subscript operation, e.g. ``x[1]``.
392392
393-
:ivar value: (node) object being sliced
393+
:ivar value: (:class:`AST`) object being sliced
394394
:ivar slice: (:class:`slice`) slice
395395
"""
396396
_fields = ('value', 'slice', 'ctx')
@@ -406,14 +406,14 @@ class UnaryOp(expr):
406406
An unary operation, e.g. ``+x``.
407407
408408
:ivar op: (:class:`unaryop`) operator
409-
:ivar operand: (node) operand
409+
:ivar operand: (:class:`AST`) operand
410410
"""
411411
_fields = ('op', 'operand')
412412
class Yield(expr):
413413
"""
414414
A yield expression, e.g. ``(yield x)``.
415415
416-
:ivar value: (node) yielded value
416+
:ivar value: (:class:`AST`) yielded value
417417
:ivar yield_loc: location of ``yield``
418418
"""
419419
_fields = ('value',)
@@ -432,7 +432,7 @@ class keyword(AST, commonloc):
432432
A keyword actual argument, e.g. in ``f(x=1)``.
433433
434434
:ivar arg: (string) name
435-
:ivar value: (node) value
435+
:ivar value: (:class:`AST`) value
436436
:ivar equals_loc: location of ``=``
437437
"""
438438
_fields = ('arg', 'value')
@@ -480,26 +480,28 @@ class slice(AST, commonloc):
480480
class ExtSlice(slice):
481481
"""
482482
The multiple slice, e.g. in ``x[0:1, 2:3]``.
483+
Note that multiple slices with only integer indexes
484+
will appear as instances of :class:`Index`.
483485
484486
:ivar dims: (:class:`slice`) sub-slices
485487
"""
486488
_fields = ('dims',)
487489
class Index(slice):
488490
"""
489-
The index, e.g. in ``x[1]``.
491+
The index, e.g. in ``x[1]`` or ``x[1, 2]``.
490492
491-
:ivar value: (node) index
493+
:ivar value: (:class:`AST`) index
492494
"""
493495
_fields = ('value',)
494496
class Slice(slice):
495497
"""
496498
The slice, e.g. in ``x[0:1]`` or ``x[0:1:2]``.
497499
498-
:ivar lower: (node or None) lower bound
499-
:ivar upper: (node or None) upper bound
500-
:ivar step: (node or None) iteration step
500+
:ivar lower: (:class:`AST`) lower bound, if any
501+
:ivar upper: (:class:`AST`) upper bound, if any
502+
:ivar step: (:class:`AST`) iteration step, if any
501503
:ivar bound_colon_loc: location of first semicolon
502-
:ivar step_colon_loc: location of second semicolon
504+
:ivar step_colon_loc: location of second semicolon, if any
503505
"""
504506
_fields = ('lower', 'upper', 'step')
505507
_locs = slice._locs + ('bound_colon_loc', 'step_colon_loc')
@@ -510,16 +512,16 @@ class Assert(stmt, keywordloc):
510512
"""
511513
The ``assert x, msg`` statement.
512514
513-
:ivar test: (node) condition
514-
:ivar msg: (node) message, if any
515+
:ivar test: (:class:`AST`) condition
516+
:ivar msg: (:class:`AST`) message, if any
515517
"""
516518
_fields = ('test', 'msg')
517519
class Assign(stmt):
518520
"""
519-
The ``=`` statement.
521+
The ``=`` statement, e.g. in ``x = 1`` or ``x = y = 1``.
520522
521-
:ivar targets: (list of assignable node) left-hand sides
522-
:ivar value: (node) right-hand side
523+
:ivar targets: (list of assignable :class:`AST`) left-hand sides
524+
:ivar value: (:class:`AST`) right-hand side
523525
:ivar op_locs: location of equality signs corresponding to ``targets``
524526
"""
525527
_fields = ('targets', 'value')
@@ -528,9 +530,9 @@ class AugAssign(stmt):
528530
"""
529531
The operator-assignment statement, e.g. ``+=``.
530532
531-
:ivar target: (assignable node) left-hand side
533+
:ivar target: (assignable :class:`AST`) left-hand side
532534
:ivar op: (:class`) operator
533-
:ivar value: (node) right-hand side
535+
:ivar value: (:class:`AST`) right-hand side
534536
"""
535537
_fields = ('target', 'op', 'value')
536538
class Break(stmt, keywordloc):
@@ -541,12 +543,12 @@ class ClassDef(stmt, keywordloc):
541543
``class x(y, z=1, *t, **u):· v`` (3.0) statement.
542544
543545
:ivar name: (string) name
544-
:ivar bases: (list of node) base classes
546+
:ivar bases: (list of :class:`AST`) base classes
545547
:ivar keywords: (list of :class:`keyword`) keyword arguments; **emitted since 3.0**
546-
:ivar starargs: (node) splat argument (if any), e.g. in ``*x``; **emitted since 3.0**
547-
:ivar kwargs: (node) keyword splat argument (if any), e.g. in ``**x``; **emitted since 3.0**
548-
:ivar body: (list of node) body
549-
:ivar decorator_list: (list of node) decorators
548+
:ivar starargs: (:class:`AST`) splat argument (if any), e.g. in ``*x``; **emitted since 3.0**
549+
:ivar kwargs: (:class:`AST`) keyword splat argument (if any), e.g. in ``**x``; **emitted since 3.0**
550+
:ivar body: (list of :class:`AST`) body
551+
:ivar decorator_list: (list of :class:`AST`) decorators
550552
:ivar keyword_loc: location of ``class``
551553
:ivar name_loc: location of name
552554
:ivar lparen_loc: location of ``(``, if any
@@ -574,9 +576,9 @@ class Exec(stmt, keywordloc):
574576
575577
**Emitted until 3.0.**
576578
577-
:ivar body: (node) code
578-
:ivar locals: (node) locals
579-
:ivar globals: (node) globals
579+
:ivar body: (:class:`AST`) code
580+
:ivar locals: (:class:`AST`) locals
581+
:ivar globals: (:class:`AST`) globals
580582
:ivar keyword_loc: location of ``exec``
581583
:ivar in_loc: location of ``in``
582584
"""
@@ -593,10 +595,10 @@ class For(stmt, keywordloc):
593595
"""
594596
The ``for x in y:· z·else:· t`` statement.
595597
596-
:ivar target: (assignable node) loop variable
597-
:ivar iter: (node) loop collection
598-
:ivar body: (list of node) code for every iteration
599-
:ivar orelse: (list of node) code if empty
598+
:ivar target: (assignable :class:`AST`) loop variable
599+
:ivar iter: (:class:`AST`) loop collection
600+
:ivar body: (list of :class:`AST`) code for every iteration
601+
:ivar orelse: (list of :class:`AST`) code if empty
600602
:ivar keyword_loc: location of ``for``
601603
:ivar in_loc: location of ``in``
602604
:ivar for_colon_loc: location of colon after ``for``
@@ -607,13 +609,13 @@ class For(stmt, keywordloc):
607609
_locs = keywordloc._locs + ('in_loc', 'for_colon_loc', 'else_loc', 'else_colon_loc')
608610
class FunctionDef(stmt, keywordloc):
609611
"""
610-
The ``def f(x):· y`` (2.6) or ``def f(x) -> t:· y`` (2.6) statement.
612+
The ``def f(x):· y`` (2.6) or ``def f(x) -> t:· y`` (3.0) statement.
611613
612614
:ivar name: (string) name
613615
:ivar args: (:class:`arguments`) formal arguments
614-
:ivar returns: (node) return type annotation; **emitted since 3.0**
615-
:ivar body: (list of node) body
616-
:ivar decorator_list: (list of node) decorators
616+
:ivar returns: (:class:`AST`) return type annotation; **emitted since 3.0**
617+
:ivar body: (list of :class:`AST`) body
618+
:ivar decorator_list: (list of :class:`AST`) decorators
617619
:ivar keyword_loc: location of ``def``
618620
:ivar name_loc: location of name
619621
:ivar arrow_loc: location of ``->``, if any; **emitted since 3.0**
@@ -635,9 +637,9 @@ class If(stmt, keywordloc):
635637
"""
636638
The ``if x:· y·else:· z`` or ``if x:· y·elif: z· t`` statement.
637639
638-
:ivar test: (node) condition
639-
:ivar body: (list of node) code if true
640-
:ivar orelse: (list of node) code if false
640+
:ivar test: (:class:`AST`) condition
641+
:ivar body: (list of :class:`AST`) code if true
642+
:ivar orelse: (list of :class:`AST`) code if false
641643
:ivar if_colon_loc: location of colon after ``if`` or ``elif``
642644
:ivar else_loc: location of ``else``, if any
643645
:ivar else_colon_loc: location of colon after ``else``, if any
@@ -685,24 +687,24 @@ class Print(stmt, keywordloc):
685687
"""
686688
The ``print >>x, y, z,`` statement.
687689
688-
**Emitted until 3.0 or ``print_function`` future flag.**
690+
**Emitted until 3.0 or until print_function future flag is activated.**
689691
690-
:ivar dest: (node) destination stream, if any
691-
:ivar values: (list of node) values to print
692+
:ivar dest: (:class:`AST`) destination stream, if any
693+
:ivar values: (list of :class:`AST`) values to print
692694
:ivar nl: (boolean) whether to print newline after values
693695
:ivar dest_loc: location of ``>>``
694696
"""
695697
_fields = ('dest', 'values', 'nl')
696698
_locs = keywordloc._locs + ('dest_loc',)
697699
class Raise(stmt, keywordloc):
698700
"""
699-
The ``raise exc, arg, traceback`` (2.x) or
701+
The ``raise exc, arg, traceback`` (2.6) or
700702
or ``raise exc from cause`` (3.0) statement.
701703
702-
:ivar exc: (node) exception type or instance
703-
:ivar cause: (node) cause of exception, if any; **emitted since 3.0**
704-
:ivar inst: (node) exception instance or argument list, if any; **emitted until 3.0**
705-
:ivar tback: (node) traceback, if any; **emitted until 3.0**
704+
:ivar exc: (:class:`AST`) exception type or instance
705+
:ivar cause: (:class:`AST`) cause of exception, if any; **emitted since 3.0**
706+
:ivar inst: (:class:`AST`) exception instance or argument list, if any; **emitted until 3.0**
707+
:ivar tback: (:class:`AST`) traceback, if any; **emitted until 3.0**
706708
:ivar from_loc: location of ``from``, if any; **emitted since 3.0**
707709
"""
708710
_fields = ('exc', 'cause', 'inst', 'tback')
@@ -711,7 +713,7 @@ class Return(stmt, keywordloc):
711713
"""
712714
The ``return x`` statement.
713715
714-
:ivar value: (node) return value, if any
716+
:ivar value: (:class:`AST`) return value, if any
715717
"""
716718
_fields = ('value',)
717719
class TryExcept(stmt, keywordloc):
@@ -720,9 +722,9 @@ class TryExcept(stmt, keywordloc):
720722
721723
**Emitted until 3.0.**
722724
723-
:ivar body: (list of node) code to try
725+
:ivar body: (list of :class:`AST`) code to try
724726
:ivar handlers: (list of :class:`ExceptHandler`) exception handlers
725-
:ivar orelse: (list of node) code if no exception
727+
:ivar orelse: (list of :class:`AST`) code if no exception
726728
:ivar keyword_loc: location of ``try``
727729
:ivar try_colon_loc: location of ``:`` after ``try``
728730
:ivar else_loc: location of ``else``
@@ -736,8 +738,8 @@ class TryFinally(stmt, keywordloc):
736738
737739
**Emitted until 3.0.**
738740
739-
:ivar body: (list of node) code to try
740-
:ivar finalbody: (list of node) code to finalize
741+
:ivar body: (list of :class:`AST`) code to try
742+
:ivar finalbody: (list of :class:`AST`) code to finalize
741743
:ivar keyword_loc: location of ``try``
742744
:ivar try_colon_loc: location of ``:`` after ``try``
743745
:ivar finally_loc: location of ``finally``
@@ -749,9 +751,9 @@ class While(stmt, keywordloc):
749751
"""
750752
The ``while x:· y·else:· z`` statement.
751753
752-
:ivar test: (node) condition
753-
:ivar body: (list of node) code for every iteration
754-
:ivar orelse: (list of node) code if empty
754+
:ivar test: (:class:`AST`) condition
755+
:ivar body: (list of :class:`AST`) code for every iteration
756+
:ivar orelse: (list of :class:`AST`) code if empty
755757
:ivar keyword_loc: location of ``while``
756758
:ivar while_colon_loc: location of colon after ``while``
757759
:ivar else_loc: location of ``else``, if any
@@ -764,7 +766,7 @@ class With(stmt, keywordloc):
764766
The ``with x as y:· z`` statement.
765767
766768
:ivar items: (list of :class:`withitem`) bindings
767-
:ivar body: (node) body
769+
:ivar body: (:class:`AST`) body
768770
:ivar keyword_loc: location of ``with``
769771
:ivar colon_loc: location of ``:``
770772
"""
@@ -786,8 +788,8 @@ class withitem(AST, commonloc):
786788
"""
787789
The ``x as y`` clause in ``with x as y:``.
788790
789-
:ivar context_expr: (node) context
790-
:ivar optional_vars: (assignable node) context binding, if any
791+
:ivar context_expr: (:class:`AST`) context
792+
:ivar optional_vars: (assignable :class:`AST`) context binding, if any
791793
:ivar as_loc: location of ``as``, if any
792794
"""
793795
_fields = ('context_expr', 'optional_vars')

‎pyparser/lexer.py

+3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def next(self, eof_token=False):
210210
the string contents if *kind* is ``strdata``,
211211
the numeric value if *kind* is ``float``, ``int`` or ``complex``,
212212
the identifier if *kind* is ``ident`` and ``None`` in any other case.
213+
214+
:param eof_token: if true, will return a token with kind ``eof``
215+
when the input is exhausted; if false, will raise ``StopIteration``.
213216
"""
214217
if len(self.queue) == 0:
215218
self._refill(eof_token)

‎upstream-doc/grammar-diff-3.1-3.2.diff

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
+comparison: expr (comp_op expr)*
2626
+# <> isn't actually a valid comparison operator in Python. It's here for the
2727
+# sake of a __future__ import described in PEP 401
28+
@@ -74 +77 @@
29+
-star_expr: ['*'] expr
30+
+star_expr: '*' expr
2831
@@ -104 +107 @@
2932
-testlist_comp: test ( comp_for | (',' test)* [','] )
3033
+testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )

0 commit comments

Comments
 (0)
Please sign in to comment.