Issue39031
Created on 2019-12-12 20:15 by lys.nikolaou, last changed 2019-12-14 10:55 by pablogsal. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 17582 | merged | lys.nikolaou, 2019-12-12 20:21 | |
| PR 17583 | closed | miss-islington, 2019-12-12 21:40 | |
| PR 17584 | merged | pablogsal, 2019-12-12 21:51 | |
| PR 17585 | closed | lys.nikolaou, 2019-12-12 21:53 | |
| PR 17589 | merged | miss-islington, 2019-12-13 14:03 | |
| PR 17596 | merged | lys.nikolaou, 2019-12-14 05:22 | |
| PR 17600 | merged | miss-islington, 2019-12-14 10:31 | |
| PR 17601 | merged | pablogsal, 2019-12-14 10:31 | |
| Messages (8) | |||
|---|---|---|---|
| msg358304 - (view) | Author: Lysandros Nikolaou (lys.nikolaou) * | Date: 2019-12-12 20:15 | |
While working on pegen, we came across an inconsistency on how line number and column offset info is stored for (el)if nodes. When parsing a very simple if-elif construct like
if a:
pass
elif b:
pass
the following parse tree gets generated:
Module(
body=[
If(
test=Name(id="a", ctx=Load(), lineno=1, col_offset=3, end_lineno=1, end_col_offset=4),
body=[Pass(lineno=2, col_offset=4, end_lineno=2, end_col_offset=8)],
orelse=[
If(
test=Name(
id="b", ctx=Load(), lineno=3, col_offset=5, end_lineno=3, end_col_offset=6
),
body=[Pass(lineno=4, col_offset=4, end_lineno=4, end_col_offset=8)],
orelse=[],
lineno=3,
col_offset=5,
end_lineno=4,
end_col_offset=8,
)
],
lineno=1,
col_offset=0,
end_lineno=4,
end_col_offset=8,
)
],
type_ignores=[],
)
There is the inconsistency that the column offset for the if statement is 0, thus the if statement starts with the keyword if, whereas the column offset for elif if 5, which means that the elif keyword is skipped.
As Guido suggests over at https://github.com/gvanrossum/pegen/issues/107#issuecomment-565135047 we could very easily change Python/ast.c so that the elif statement start with the elif keyword as well.
I have a PR ready!
|
|||
| msg358306 - (view) | Author: miss-islington (miss-islington) | Date: 2019-12-12 21:40 | |
New changeset 025a602af7ee284d8db6955c26016f3f27d35536 by Miss Islington (bot) (Lysandros Nikolaou) in branch 'master': bpo-39031: Include elif keyword when producing lineno/col-offset info for if_stmt (GH-17582) https://github.com/python/cpython/commit/025a602af7ee284d8db6955c26016f3f27d35536 |
|||
| msg358308 - (view) | Author: Pablo Galindo Salgado (pablogsal) * | Date: 2019-12-12 22:12 | |
Hmmm, there is some problem with the CI and the 3.7 branch. Seems like Travis CI is giving some problems again.... I will investigate or maybe ask Brett to make the check not required again (we still have Azure Pipelines, testing the same thing). |
|||
| msg358309 - (view) | Author: Pablo Galindo Salgado (pablogsal) * | Date: 2019-12-12 22:12 | |
The same thing happens with 3.8..... |
|||
| msg358332 - (view) | Author: Pablo Galindo Salgado (pablogsal) * | Date: 2019-12-13 14:04 | |
New changeset 0ed45d0cbfc7579dfc5527c19aa6e4bb696db2e0 by Pablo Galindo in branch '3.7': [3.7] bpo-39031: Include elif keyword when producing lineno/col-offset info for if_stmt (GH-17582) (#17584) https://github.com/python/cpython/commit/0ed45d0cbfc7579dfc5527c19aa6e4bb696db2e0 |
|||
| msg358338 - (view) | Author: Pablo Galindo Salgado (pablogsal) * | Date: 2019-12-13 16:22 | |
New changeset 3b18b17efcee6f968cf85c543254b3611311e9f4 by Pablo Galindo (Miss Islington (bot)) in branch '3.8': bpo-39031: Include elif keyword when producing lineno/col-offset info for if_stmt (GH-17582) (GH-17589) https://github.com/python/cpython/commit/3b18b17efcee6f968cf85c543254b3611311e9f4 |
|||
| msg358376 - (view) | Author: Lysandros Nikolaou (lys.nikolaou) * | Date: 2019-12-14 04:53 | |
There was a bug in my last PR, hopefully I will get a fix some time later today.
The bug is as follows: I only updated the asdl_seq_SET call for an elif without an else, if an else is included then the behavior is like before.
After my last PR it looks like this, parsing
2:if a:
3: pass
4:elif b:
5: pass
outputs the following AST:
Module(
body=[
If(
test=Name(id="a", ctx=Load(), lineno=2, col_offset=3, end_lineno=2, end_col_offset=4),
body=[Pass(lineno=3, col_offset=4, end_lineno=3, end_col_offset=8)],
orelse=[
If(
test=Name(
id="b", ctx=Load(), lineno=4, col_offset=5, end_lineno=4, end_col_offset=6
),
body=[Pass(lineno=5, col_offset=4, end_lineno=5, end_col_offset=8)],
orelse=[],
lineno=4,
col_offset=0,
end_lineno=5,
end_col_offset=8,
)
],
lineno=2,
col_offset=0,
end_lineno=5,
end_col_offset=8,
)
],
type_ignores=[],
)
On the other hand parsing
2:if a:
3: pass
4:elif b:
5: pass
6:else:
7: pass
outputs
Module(
body=[
If(
test=Name(
id="a",
ctx=Load(),
lineno=2,
col_offset=3,
end_lineno=2,
end_col_offset=4,
),
body=[Pass(lineno=3, col_offset=4, end_lineno=3, end_col_offset=8)],
orelse=[
If(
test=Name(
id="b",
ctx=Load(),
lineno=4,
col_offset=5,
end_lineno=4,
end_col_offset=6,
),
body=[Pass(lineno=5, col_offset=4, end_lineno=5, end_col_offset=8)],
orelse=[
Pass(lineno=7, col_offset=4, end_lineno=7, end_col_offset=8)
],
lineno=4,
col_offset=5,
end_lineno=7,
end_col_offset=8,
)
],
lineno=2,
col_offset=0,
end_lineno=7,
end_col_offset=8,
)
],
type_ignores=[],
)
|
|||
| msg358387 - (view) | Author: Pablo Galindo Salgado (pablogsal) * | Date: 2019-12-14 10:55 | |
Thanks, Lysandros for the quick fix! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2019-12-14 10:55:43 | pablogsal | set | status: open -> closed resolution: fixed messages: + msg358387 |
| 2019-12-14 10:36:22 | pablogsal | set | status: closed -> open resolution: fixed -> (no value) |
| 2019-12-14 10:31:52 | pablogsal | set | pull_requests: + pull_request17070 |
| 2019-12-14 10:31:22 | miss-islington | set | pull_requests: + pull_request17069 |
| 2019-12-14 05:22:45 | lys.nikolaou | set | pull_requests: + pull_request17068 |
| 2019-12-14 04:53:45 | lys.nikolaou | set | messages: + msg358376 |
| 2019-12-13 20:30:27 | gvanrossum | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-12-13 16:22:24 | pablogsal | set | messages: + msg358338 |
| 2019-12-13 14:04:18 | pablogsal | set | messages: + msg358332 |
| 2019-12-13 14:03:47 | miss-islington | set | pull_requests: + pull_request17061 |
| 2019-12-12 22:12:41 | pablogsal | set | messages: + msg358309 |
| 2019-12-12 22:12:06 | pablogsal | set | messages: + msg358308 |
| 2019-12-12 21:53:23 | lys.nikolaou | set | pull_requests: + pull_request17059 |
| 2019-12-12 21:51:49 | pablogsal | set | pull_requests: + pull_request17058 |
| 2019-12-12 21:40:37 | miss-islington | set | pull_requests: + pull_request17057 |
| 2019-12-12 21:40:27 | miss-islington | set | nosy:
+ miss-islington messages: + msg358306 |
| 2019-12-12 21:14:46 | pablogsal | set | components: + Interpreter Core |
| 2019-12-12 21:14:17 | pablogsal | set | versions: + Python 3.7 |
| 2019-12-12 21:14:02 | pablogsal | set | nosy:
+ pablogsal |
| 2019-12-12 20:21:36 | lys.nikolaou | set | keywords:
+ patch stage: patch review pull_requests: + pull_request17056 |
| 2019-12-12 20:16:24 | lys.nikolaou | set | title: Inconsistent lineno and col_offset info when parsing elif -> Inconsistency with lineno and col_offset info when parsing elif |
| 2019-12-12 20:15:07 | lys.nikolaou | create | |