Skip to content

os.path.ismount() doesn't properly use byte-paths from an os.DirEntry #96192

Closed
@calestyo

Description

@calestyo

Bug report

It seems that os.path.ismount() doesn't properly use a bytes-path from an os.DirEntry object (despite both claiming to support/be PathLike).

Take e.g. the following code, when called with a bytes path:

def scandirtree(path=b".", xdev=True):
    for p in os.scandir(path):
        yield p
        if p.is_dir(follow_symlinks=False)   and   ( not xdev  or  not os.path.ismount(p) ):
            yield from scandirtree(p, xdev)

That fails with:

Traceback (most recent call last):
  File "/home/calestyo/prj/generate-file-list/src/./generate-file-list", line 65, in <module>
    main()
  File "/home/calestyo/prj/generate-file-list/src/./generate-file-list", line 52, in main
    for p in scandirtree(ap, args.xdev):
  File "/home/calestyo/prj/generate-file-list/src/./generate-file-list", line 25, in scandirtree
    if p.is_dir(follow_symlinks=False)   and   ( not xdev  or  not os.path.ismount(p) ):
  File "/usr/lib/python3.10/posixpath.py", line 201, in ismount
    parent = join(path, '..')
  File "/usr/lib/python3.10/posixpath.py", line 90, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib/python3.10/genericpath.py", line 155, in _check_arg_types
    raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

See also https://discuss.python.org/t/bug-in-os-path-ismount-or-perhaps-os-direntry/18406

Your environment

  • CPython versions tested on: 3.10.6
  • Operating system and architecture: Debian sid, x86_64

Cheers,
Chris.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixeseasystdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions