Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

[DO NOT MERGE] Fix def line numbers for decorated nodes #61

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ parsers. `typed_ast` runs on Python 3.3-3.7 on Linux, OS X and Windows.

## Development Philosophy

This project is a (mostly) drop-in replacement for the builtin `ast` module. It is
This project is a near drop-in replacement for the builtin `ast` module. It is
intended to be bug-for-bug compatible and behave identically, except for the
presence of a few additional fields on the returned classes and a few
additional optional arguments to the `parse` call. Therefore, `typed_ast` will
not accept any bugfixes for bugs in `ast` -- they should be fixed upstream
instead. To avoid feature bloat, any new features for `typed_ast` should have
the potential to be broadly useful and not be built just for one niche usecase
or in a manner such that only one project can use them.
additional optional arguments to the `parse` call. From time to time we may
backport important bug fixes from upstream. Therefore, `typed_ast` will not
accept most bugfixes for bugs in `ast`. Before a bug fix is considered, it
must be merged upstream first. In other words, we only will take select
backports from the upstream ast module. To avoid feature bloat, any new
features for `typed_ast` should have the potential to be broadly useful and not
be built just for one niche usecase or in a manner such that only one project
can use them.

### Incompatabilities

Expand All @@ -40,11 +43,11 @@ not treated as keywords.
The `ast3` parser produces the AST from a recent version of Python 3
(currently Python 3.6). When new versions of Python 3 are released, it will be
updated to match any changes in their AST. (For rationale and technical
details, see [here](update_process.md).) The AST it currently produces is described in
[ast3/Parser/Python.asdl](ast3/Parser/Python.asdl). If you wish to limit
parsing to older versions of Python 3, `ast3` can be configured to to give a
SyntaxError for new syntax features introduced beyond a given Python version.
For more information, see the module docstring in
details, see [here](update_process.md).) The AST it currently produces is
described in [ast3/Parser/Python.asdl](ast3/Parser/Python.asdl). If you wish
to limit parsing to older versions of Python 3, `ast3` can be configured to to
give a SyntaxError for new syntax features introduced beyond a given Python
version. For more information, see the module docstring in
[typed\_ast/ast3.py](typed_ast/ast3.py).

### ast27
Expand All @@ -64,6 +67,8 @@ Note: as these parsers consider type comments part of the grammar, incorrectly
placed type comments are considered syntax errors.

## Updates and Releases
To update `typed_ast` for new major Python releases, see [`update_process.md`](update_process.md).
To update `typed_ast` for new major Python releases, see
[`update_process.md`](update_process.md).

To make a new `typed_ast` release, see [`release_process.md`](release_process.md).
To make a new `typed_ast` release, see
[`release_process.md`](release_process.md).
6 changes: 0 additions & 6 deletions ast27/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,6 @@ ast_for_decorated(struct compiling *c, const node *n)
} else if (TYPE(CHILD(n, 1)) == classdef) {
thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq);
}
/* we count the decorators in when talking about the class' or
function's line number */
if (thing) {
thing->lineno = LINENO(n);
thing->col_offset = n->n_col_offset;
}
return thing;
}

Expand Down
6 changes: 0 additions & 6 deletions ast3/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1879,12 +1879,6 @@ ast_for_decorated(struct compiling *c, const node *n)
} else if (TYPE(CHILD(n, 1)) == async_funcdef) {
thing = ast_for_async_funcdef(c, CHILD(n, 1), decorator_seq);
}
/* we count the decorators in when talking about the class' or
* function's line number */
if (thing) {
thing->lineno = LINENO(n);
thing->col_offset = n->n_col_offset;
}
return thing;
}

Expand Down
2 changes: 2 additions & 0 deletions typed_ast/ast27.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
lines which have been `# type: ignore`d.
- `Str` has a `kind` string field which preserves the original string
prefix, so that `ast27.parse('br"test"').body[0].value.kind == 'br'`.
- Fixed line number information for decorated AST nodes.
(Based on https://github.com/python/cpython/pull/9731)

An abstract syntax tree can be generated by using the `parse()`
function from this module. The result will be a tree of objects whose
Expand Down
2 changes: 2 additions & 0 deletions typed_ast/ast3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
lines which have been `# type: ignore`d.
- `Str` has a `kind` string field which preserves the original string
prefix, so that `ast3.parse('u"test"').body[0].value.kind == 'u'`.
- Fixed line number information for decorated AST nodes.
(Based on https://github.com/python/cpython/pull/9731)

An abstract syntax tree can be generated by using the `parse()`
function from this module. The result will be a tree of objects whose
Expand Down