classification
Title: compile raises SyntaxError with undocumented lineno attribute None
Type: behavior Stage: resolved
Components: Parser Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fweimer, lys.nikolaou, miss-islington, pablogsal
Priority: normal Keywords: 3.10regression, 3.9regression, patch

Created on 2021-06-13 11:25 by fweimer, last changed 2021-06-14 17:27 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26712 merged pablogsal, 2021-06-13 22:13
PR 26722 merged miss-islington, 2021-06-14 16:46
PR 26723 merged pablogsal, 2021-06-14 16:49
Messages (5)
msg395740 - (view) Author: Florian Weimer (fweimer) Date: 2021-06-13 11:25
This example results in an undocumented value None for the lineno attribute:

```
source = b"\xef\xbb\xbf#coding: utf8\nprint('\xe6\x88\x91')\n"

try:
    compile(source, filename="example.py", mode="exec")
except SyntaxError as e:
    print(str(e))
    print(type(e.lineno))
```

Output:

```
encoding problem: utf8 with BOM
<class 'NoneType'>
```

Seen with python3-3.9.5-2.fc33.x86_64.

python3-3.8.10-1.fc32.x86_64 used a lineno value of 0 (type int).
msg395763 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-13 21:31
Well, in both cases this means that the line number is not available. I think None is a bit cleaner in this regard.
msg395778 - (view) Author: Florian Weimer (fweimer) Date: 2021-06-14 07:27
I suppose changing the documentation to mention `None` would be possible as well, but restoring the old behavior works for me too. Thanks.
msg395811 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-14 16:46
New changeset 507ed6fa1d6661e0f8e6d3282764aa9625a99594 by Pablo Galindo in branch 'main':
bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712)
https://github.com/python/cpython/commit/507ed6fa1d6661e0f8e6d3282764aa9625a99594
msg395814 - (view) Author: miss-islington (miss-islington) Date: 2021-06-14 17:08
New changeset 133cddf76e8265536c584872351c191e3afd66a2 by Miss Islington (bot) in branch '3.10':
bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712)
https://github.com/python/cpython/commit/133cddf76e8265536c584872351c191e3afd66a2
msg395815 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-14 17:08
New changeset 0d0a9eaa822658679cc2b65f125ab74bfd4aedfe by Pablo Galindo in branch '3.9':
[3.9] bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712). (GH-26723)
https://github.com/python/cpython/commit/0d0a9eaa822658679cc2b65f125ab74bfd4aedfe
History
Date User Action Args
2021-06-14 17:27:22pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-06-14 17:08:00pablogsalsetmessages: + msg395815
2021-06-14 17:08:00miss-islingtonsetmessages: + msg395814
2021-06-14 16:49:01pablogsalsetpull_requests: + pull_request25313
2021-06-14 16:46:32pablogsalsetmessages: + msg395811
2021-06-14 16:46:20miss-islingtonsetkeywords: + patch
nosy: + miss-islington
pull_requests: + pull_request25312
2021-06-14 07:27:58fweimersetmessages: + msg395778
2021-06-13 22:13:30pablogsalsetkeywords: + 3.9regression, 3.10regression, - patch
2021-06-13 22:13:19pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25300
2021-06-13 21:31:33pablogsalsetmessages: + msg395763
2021-06-13 11:25:16fweimercreate