Skip to content

Pdb doesn't handle anonymous pipe symlinks #142315

@johnslavik

Description

@johnslavik

Bug report

Bug description:

To reproduce (Bash):

❯ ./python -m pdb <(echo 'print("Hello world!")')
Error: /dev/fd/63 does not exist

This isn't exactly right. /dev/fd/63 was a symlink to an existing anonymous pipe, but it was checked after being processed with os.path.realpath (which made the path unusable for open or stat -- GH-99390):

cpython/Lib/pdb.py

Lines 184 to 190 in 706fdda

class _ScriptTarget(_ExecutableTarget):
def __init__(self, target):
self._target = os.path.realpath(target)
if not os.path.exists(self._target):
print(f'Error: {target} does not exist')
sys.exit(1)

Technically, this is a 3.11 regression caused by https://github.com/python/cpython/pull/26992/files#r663030110.
The new behavior was preserved in the refactor of executable targets in Pdb (GH-112570). Before these two patches, os.path.realpath was only used in Pdb to figure out the directory to be set as sys.path[0] since GH-23338. Prior to that, os.path.realpath wasn't used in Pdb at all.

To fix this edge case, I think we could simply bring back the old behavior of passing the raw path to system functions and continue to use the real path elsewhere.

A dead-simple workaround is to just use regular files.

CC @jaraco @iritkatriel @gaogaotiantian
CC @ZeroIntensity (mentorship): stdlib, 3.13 & 3.14 (unless it's a feature at this point), 3.15. Not sure if I would give this OS-specific labels.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions