Google Grupper støtter ikke lenger nye Usenet-innlegg eller -abonnementer. Historisk innhold er fortsatt synlig.

Resolution of paths in tracebacks

Sett 66 ganger
Hopp til første uleste melding

Vishal Chandratreya

ulest,
31. mai 2023, 11:45:5031.05.2023
til
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).

Grant Edwards

ulest,
31. mai 2023, 12:25:3531.05.2023
til
On 2023-05-31, Vishal Chandratreya <vpa...@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


0 nye meldinger