This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: AttributeError: incorrect line identified in Python 3.10
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, alexmojaki, aroberge, pablogsal
Priority: Keywords:

Created on 2021-07-07 09:23 by aroberge, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg397067 - (view) Author: Andre Roberge (aroberge) * Date: 2021-07-07 09:23
Consider the following program

# example.py
one = 1
two = "two"
a = [one
    .
    two]

Running this program with Python versions before 3.10, yields the following traceback:

Traceback (most recent call last):
  File "C:\Users\andre\example.py", line 3, in <module>
    a = [one
AttributeError: 'int' object has no attribute 'two'

The line shown correctly includes the 'int' object. I have verified that this is the case for Python 3.6 to 3.9 inclusively.

However, with Python version 3.10.0b3, the following traceback is generated:

Traceback (most recent call last):
  File "C:\Users\andre\example.py", line 5, in <module>
    two]
AttributeError: 'int' object has no attribute 'two'
msg397074 - (view) Author: Alex Hall (alexmojaki) Date: 2021-07-07 11:38
I believe this is the outcome of https://bugs.python.org/issue39316 which I filed, so I'm pulling in . Naturally I think the new behaviour is not a bug but a feature.

I think it's more important for the traceback to show the attribute access (`two`) than the value (`one`). That's what the frame was doing at the time which led to the error.

The difference becomes even more important when calling a method with no arguments. Given this script:

class A:
    def b(self):
        1 / 0


x = (
    A()
        .b()
)


The 3.9 traceback points to the line with `A()` in the `<module>` frame, while 3.10 correctly points to `.b()`, which makes the following line 'in b' make more sense.

Where the old behaviour has really gotten to me is when I run the pycharm debugger and put a breakpoint on the .b() line and it never gets hit. Not being sure what lines 'count', I sometimes defensively put breakpoints on a cluster of lines, then spend more time removing them later. Having that fixed in 3.10 is great.
msg397075 - (view) Author: Alex Hall (alexmojaki) Date: 2021-07-07 11:38
(meant to say "so I'm pulling in @Mark.Shannon)
msg397089 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-07 14:30
Mark, take a look as soon as possible as beta4 is this week
msg397097 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-07-07 14:58
This is a tricky one.
Which is the "correct" line appears to be subjective.

I'm inclined to leave it as is, as the tracing sequence seems better in the case of method chaining.
See https://github.com/python/cpython/blob/main/Lib/test/test_compile.py#L890
msg397098 - (view) Author: Andre Roberge (aroberge) * Date: 2021-07-07 15:03
While I filed the original report, I am in agreement that accurate information for debugging tools is definitely more important than the quick summary shown in the traceback, and that the change likely represents an improvement in situations more realistic than the contrived example I gave.
msg397099 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-07 15:20
> I'm inclined to leave it as is

I am fine with that, if you think this is not a bug, close the issue and remove the release blocker :)
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88742
2021-07-08 08:10:27Mark.Shannonsetpriority: release blocker ->
status: open -> closed
resolution: not a bug
stage: resolved
2021-07-07 15:20:01pablogsalsetmessages: + msg397099
2021-07-07 15:03:03arobergesetmessages: + msg397098
2021-07-07 14:58:56Mark.Shannonsetmessages: + msg397097
2021-07-07 14:30:28pablogsalsetpriority: normal -> release blocker
nosy: + pablogsal
messages: + msg397089

2021-07-07 11:39:00alexmojakisetmessages: + msg397075
2021-07-07 11:38:26alexmojakisetnosy: + Mark.Shannon, alexmojaki
messages: + msg397074

components: + Interpreter Core
type: behavior
2021-07-07 09:23:56arobergecreate