You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Negative line number in stacktrace exception #101400
changed the title [-]The following code snippet generates a stacktrace exception pointing to a invalid line number (-1):
```python
with object() as obj:
break
```
Example:
```bash
$ echo 'with object() as obj:\n\tbreak' > main.py
$ python main.py
File "/home/kartz/main.py", line -1
SyntaxError: 'break' outside loop
```
This is reproducible with Python 3.10, 3.11 and latest [master](https://github.com/python/cpython/commit/666c0840dcac9941fa41ec619fef8d45cd849a0b). I could not reproduce this on Python versions older than <3.10.
[/-][+]Negative line number in stacktrace exception[/+]on Jan 29, 2023
Activity
[-]The following code snippet generates a stacktrace exception pointing to a invalid line number (-1): ```python with object() as obj: break ``` Example: ```bash $ echo 'with object() as obj:\n\tbreak' > main.py $ python main.py File "/home/kartz/main.py", line -1 SyntaxError: 'break' outside loop ``` This is reproducible with Python 3.10, 3.11 and latest [master](https://github.com/python/cpython/commit/666c0840dcac9941fa41ec619fef8d45cd849a0b). I could not reproduce this on Python versions older than <3.10. [/-][+]Negative line number in stacktrace exception[/+]corona10 commentedon Jan 29, 2023
@iritkatriel
The bug is triggered from this line:
cpython/Python/compile.c
Line 2069 in 666c084
Same issue with continue
corona10 commentedon Jan 29, 2023
This kind of fix will solve the issue, but I am not sure this is the right approach.
iritkatriel commentedon Jan 29, 2023
@corona10 your fix looks right. Do you want to make a PR? We would need a couple of tests for this.
corona10 commentedon Jan 29, 2023
I will submit the patch ;)
pythongh-101400: Restore continue/break loc for the non-loop case
pythongh-101400: Restore continue/break loc for the non-loop case
gh-101400: Fix incorrect lineno in exception message on continue/breaâĶ
[3.11] pythongh-101400: Fix incorrect lineno in exception message on âĶ
[3.10] pythongh-101400: Fix incorrect lineno in exception message on âĶ
[3.11] pythongh-101400: Fix incorrect lineno in exception message on âĶ
[3.10] gh-101400: Fix incorrect lineno in exception message on continâĶ (
[3.11] gh-101400: Fix incorrect lineno in exception message on continâĶ (
corona10 commentedon Jan 31, 2023
Now we can close the issue. Please let me know if we have to reopen the issue.
Thanks for the report @Kartatz
And thanks for the kind reviews!! @iritkatriel :)
pythongh-101400: Fix incorrect lineno in exception message on continuâĶ