classification
Title: File paths in exception traceback resolve symlinks
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.6, Python 2.7
process
Status: pending Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Paul Pinterits, iritkatriel
Priority: normal Keywords:

Created on 2017-08-27 20:17 by Paul Pinterits, last changed 2020-11-19 11:35 by iritkatriel.

Messages (2)
msg300926 - (view) Author: Paul Pinterits (Paul Pinterits) Date: 2017-08-27 20:17
The file paths displayed in exception tracebacks have their symlinks resolved. I would prefer if the "original" path could be displayed instead, because resolved symlinks result in unexpected paths in the traceback and can be quite confusing.

An example:

rawing@localhost ~> cat test_scripts/A.py
import B
B.throw()

rawing@localhost ~> cat test_scripts/B.py
def throw():
    raise ValueError

rawing@localhost ~> ln -s test_scripts test_symlink

rawing@localhost ~> python3 test_symlink/A.py
Traceback (most recent call last):
  File "test_symlink/A.py", line 2, in <module>
    B.throw()
  File "/home/rawing/test_scripts/B.py", line 2, in throw
    raise ValueError
ValueError

As you can see, even though both scripts reside in the same directory, the file paths displayed in the traceback look very different. At first glance, it looks like B is in a completely different place than A.
Furthermore, this behavior tends to trip up IDEs - PyCharm for example does not understand that test_scripts/B.py and test_symlink/B.py are the same file, so I end up having the same file opened in two different tabs.

Would it be possible to change this behavior and have "/home/rawing/test_symlink/B.py" show up in the traceback instead?
msg381405 - (view) Author: Irit Katriel (iritkatriel) * (Python triager) Date: 2020-11-19 11:35
Here is a case where the opposite was requested: 
https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1179979
There they want the traceback to be the same regardless of which symlink the script was found by.

I think a change like the one you are proposing here should be discussed on python-ideas. Would you like to bring it up there?
History
Date User Action Args
2020-11-19 11:35:21iritkatrielsetstatus: open -> pending
nosy: + iritkatriel
messages: + msg381405

2017-08-27 20:17:56Paul Pinteritscreate