Mailing List Archive

Resolution of paths in tracebacks
When an exception occurs, the full path to the file from which it
originates is displayed, but redundant elements are not removed. For
instance:
$ ./python ./foo
Traceback (most recent call last):
File "/home/User/cpython/./foo", line 4, in <module>
a()
File "/home/User/cpython/./foo", line 3, in a
def a(): raise ValueError
ValueError
This happens because the function _Py_abspath (in Python/fileutils.c)
appends relative_path_to_file to absolute_path_to_current_working_directory.
Not sure if this should be treated as a bug, because the definition of
'absolute path' is not clear. Does it mean a path starting from the root
directory, or a path without redundant elements? The os module, for
instance, does the following.
$ ./python
>>> import os.path
>>> os.path.isabs('/home/..')
True
>>> os.path.abspath('/home/..')
'/'
Either way: should the traceback display the path without redundant
elements?

I am using CPython 3.13.0a0 (595ffddb33e95d8fa11999ddb873d08e3565d2eb).
--
https://mail.python.org/mailman/listinfo/python-list
Re: Resolution of paths in tracebacks [ In reply to ]
On 2023-05-31, Vishal Chandratreya <vpaijc@gmail.com> wrote:
> When an exception occurs, the full path to the file from which it
> originates is displayed, but redundant elements are not removed. For
> instance:
> $ ./python ./foo
> Traceback (most recent call last):
> File "/home/User/cpython/./foo", line 4, in <module>
> a()
> File "/home/User/cpython/./foo", line 3, in a
> def a(): raise ValueError
> ValueError
> This happens because the function _Py_abspath (in Python/fileutils.c)
> appends relative_path_to_file to absolute_path_to_current_working_directory.
> Not sure if this should be treated as a bug, because the definition of
> 'absolute path' is not clear. Does it mean a path starting from the root
> directory, or a path without redundant elements?

The former:

https://www.linuxfoundation.org/blog/blog/classic-sysadmin-absolute-path-vs-relative-path-in-linux-unix


--
https://mail.python.org/mailman/listinfo/python-list