
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2018-05-03 10:15 bylevkivskyi, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 11605 | merged | levkivskyi,2019-01-18 09:46 | |
| PR 11605 | merged | levkivskyi,2019-01-18 09:46 | |
| PR 11605 | merged | levkivskyi,2019-01-18 09:46 | |
| PR 10497 | emilyemorehouse,2019-01-22 22:56 | ||
| PR 14214 | merged | levkivskyi,2019-06-19 00:04 | |
| PR 14215 | merged | miss-islington,2019-06-19 00:19 | |
| Messages (15) | |||
|---|---|---|---|
| msg316117 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2018-05-03 10:15 | |
Some Python tools (in particular I am interested in type checkers) will benefit from knowing where a given expression ends to indicate/highlight location of an error in the source code. Other tools and IDEs may have also some other benefits. Currently such tools need to use some hacks and/or custom parser to find the end line and end column of an expression, while it would be more straightforward to just add this information to every AST node by CPythons own parser.This will increase memory usage, but expectation is that this effect will be minor.What do you think? | |||
| msg330180 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2018-11-21 08:13 | |
I like this. This can help to generate more meaningful error messages at compile and run time. | |||
| msg330207 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2018-11-21 15:26 | |
This may be a duplicate ofissue22616.See alsoissue16795,issue21295,issue33211,issue34876. | |||
| msg330287 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2018-11-22 22:38 | |
issue22616 is a bit different (proposing line/column ranges instead of just endline/endcolumn). I am happy to close this one in favor ofissue22616 if we agree that we will go with endline/endcolumn.I can't guarantee, but likely I will work on this during winter holidays, unless there are some objections, or unless someone will do this before :-) | |||
| msg333575 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-01-13 23:44 | |
FYI, I started working on this. I will have PR ready end of next week.Serhiy, I don't think we should keep both this andissue22616 open. Which one would you prefer to close? | |||
| msg333583 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2019-01-14 05:33 | |
This idea seems reasonable. Most of the AST nodes have a span and it would be nice to know what that is. I'm sure we will find use cases though I doubt that many compiler syntax errors would benefit (since a syntax error means that we don't have a completely matched grammar rule).BTW, does this information have to be added by the parser or could there be am AST module function that deduces the end locations from the start location of next sibling node or from the parent node? If so, it may still be possible get the benefit without slowing down or complicating the parser logic.Do we know what other languages do (carry the full span info in the AST or deduce the span after the fact)? I don't know what the best practices are in this regard.One other thought: We should be careful not to impair existing AST capabilities that support code rewriting and movement (i.e. refactoring tools). The copy_location() and fix_missing_locations() functions would need to be updated as well. | |||
| msg333587 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-01-14 07:18 | |
It is up to you Ivan.The end location can not be deduces from the start location of next sibling node or from the parent node. For example, the AST for the expression "foo.bar.baz" does not contain information for the end location of "foo.bar". | |||
| msg333608 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-01-14 11:18 | |
> I'm sure we will find use cases though I doubt that many compiler syntax errors would benefit (since a syntax error means that we don't have a completely matched grammar rule).This is mostly useful for code analysis tools and IDEs.> BTW, does this information have to be added by the parser or could there be am AST module function that deduces the end locations from the start location of next sibling node or from the parent node?There may be some other ways to do it, but currently I am adding both `end_lineno` and `end_col_offset` to AST, and `n_end_lineno` and `n_end_col_offset` in CST. The latter are needed to easily take care of situations like `a + (b )`, and other corner cases. I could imagine it is possible to live with only end position information in AST to save some memory, but then the code will be much harder to maintain. We can discuss details in the PR.> Do we know what other languages do (carry the full span info in the AST or deduce the span after the fact)?I didn't do real research, but quick browsing shows carrying the end position info is quite common. But more importantly as Serhiy noted, deducing might be just not possible in some situations.> It is up to you Ivan.OK, I will close the other one as superseded by this issue. | |||
| msg333617 -(view) | Author: Aivar Annamaa (Aivar.Annamaa)* | Date: 2019-01-14 13:06 | |
I strongly support this feature, because my IDE (https://thonny.org) needs to highlight AST nodes in the source code.There would be many interested parties if you count the stars of this project:https://github.com/gristlabs/asttokens | |||
| msg334205 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-01-22 11:18 | |
New changeset9932a22897ef9905161dac7476e6976370e13515 by Ivan Levkivskyi in branch 'master':bpo-33416: Add end positions to Python AST (GH-11605)https://github.com/python/cpython/commit/9932a22897ef9905161dac7476e6976370e13515 | |||
| msg334228 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-01-22 18:54 | |
Buildbots are green, this can be now closed. | |||
| msg334300 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-01-24 13:33 | |
Re-opening to track renaming of potentially public PyNode_AddChild() and PyParser_AddToken(). | |||
| msg344507 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-06-04 00:33 | |
So what was the conclusion about PyCode_New()? Situation is quite similar here (except that these functions are used less often). Should we just document the changes in What's New? | |||
| msg344519 -(view) | Author: Guido van Rossum (gvanrossum)*![]() | Date: 2019-06-04 02:38 | |
It seems we're keeping the new PyCode_New() signature, so we can do the same here. Just document it; a versionchanged (if there isn't one yet) and a mention in What's New sound appropriate. | |||
| msg346015 -(view) | Author: miss-islington (miss-islington) | Date: 2019-06-19 00:33 | |
New changeset45da7437f54b4a6bdb8b4ba5a0f13f44a24eec39 by Miss Islington (bot) in branch '3.8':[3.8]bpo-33416: Document changes in PyNode_AddChild and PyParser_AddToken (GH-14214) (GH-14215)https://github.com/python/cpython/commit/45da7437f54b4a6bdb8b4ba5a0f13f44a24eec39 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:00 | admin | set | github: 77597 |
| 2019-06-19 00:34:46 | levkivskyi | set | keywords:patch,patch,patch status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-06-19 00:33:37 | miss-islington | set | nosy: +miss-islington messages: +msg346015 |
| 2019-06-19 00:19:57 | miss-islington | set | pull_requests: +pull_request14054 |
| 2019-06-19 00:04:46 | levkivskyi | set | pull_requests: +pull_request14052 |
| 2019-06-04 02:38:22 | gvanrossum | set | keywords:patch,patch,patch messages: +msg344519 |
| 2019-06-04 00:33:12 | levkivskyi | set | keywords:patch,patch,patch messages: +msg344507 |
| 2019-01-24 13:33:56 | levkivskyi | set | status: closed -> open keywords:patch,patch,patch nosy: +vstinner messages: +msg334300 resolution: fixed -> (no value) stage: resolved -> patch review |
| 2019-01-22 22:56:19 | emilyemorehouse | set | pull_requests: +pull_request11441 |
| 2019-01-22 18:54:21 | levkivskyi | set | status: open -> closed messages: +msg334228 keywords:patch,patch,patch resolution: fixed stage: patch review -> resolved |
| 2019-01-22 11:18:26 | levkivskyi | set | messages: +msg334205 |
| 2019-01-18 09:50:20 | vstinner | set | keywords:patch,patch,patch nosy: -vstinner |
| 2019-01-18 09:47:02 | levkivskyi | set | keywords: +patch stage: patch review pull_requests: +pull_request11331 |
| 2019-01-18 09:46:44 | levkivskyi | set | keywords: +patch stage: (no value) pull_requests: +pull_request11330 |
| 2019-01-18 09:46:27 | levkivskyi | set | keywords: +patch stage: (no value) pull_requests: +pull_request11329 |
| 2019-01-14 13:06:40 | Aivar.Annamaa | set | nosy: +Aivar.Annamaa messages: +msg333617 |
| 2019-01-14 11:24:42 | levkivskyi | link | issue22616 superseder |
| 2019-01-14 11:18:39 | levkivskyi | set | messages: +msg333608 |
| 2019-01-14 07:18:01 | serhiy.storchaka | set | messages: +msg333587 |
| 2019-01-14 05:33:17 | rhettinger | set | nosy: +rhettinger messages: +msg333583 |
| 2019-01-13 23:44:05 | levkivskyi | set | messages: +msg333575 |
| 2018-11-22 22:38:53 | levkivskyi | set | messages: +msg330287 |
| 2018-11-21 15:26:14 | serhiy.storchaka | set | messages: +msg330207 |
| 2018-11-21 08:44:56 | rhettinger | set | nosy: +brett.cannon |
| 2018-11-21 08:13:34 | serhiy.storchaka | set | messages: +msg330180 |
| 2018-05-03 10:15:25 | levkivskyi | create | |