X Tutup
The Wayback Machine - https://web.archive.org/web/20221208222412/https://github.com/python/cpython/issues/96192
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
calestyo opened this issue Aug 22, 2022 · 3 comments
Closed
3 tasks done

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

calestyo opened this issue Aug 22, 2022 · 3 comments
Labels
3.10 3.11 3.12 easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@calestyo
Copy link
Contributor

calestyo commented Aug 22, 2022

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.

@calestyo calestyo added the type-bug An unexpected behavior, bug, or error label Aug 22, 2022
@eryksun eryksun added stdlib Python modules in the Lib dir 3.11 3.10 3.12 easy labels Aug 23, 2022
@eryksun
Copy link
Contributor

eryksun commented Aug 23, 2022

posixpath.ismount() mistakenly checks isinstance(path, bytes) without first ensuring that the type is str or bytes via path = os.fspath(path).

@calestyo
Copy link
Contributor Author

calestyo commented Aug 23, 2022

Shall I provide a patch?

JelleZijlstra added a commit that referenced this issue Nov 14, 2022
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 14, 2022
…ythonGH-96194)

(cherry picked from commit 367f552)

Co-authored-by: Christoph Anton Mitterer <calestyo@scientia.org>
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 14, 2022
…ythonGH-96194)

(cherry picked from commit 367f552)

Co-authored-by: Christoph Anton Mitterer <calestyo@scientia.org>
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@hauntsaninja
Copy link
Contributor

hauntsaninja commented Nov 29, 2022

Thanks, looks like this has been fixed!

miss-islington added a commit that referenced this issue Nov 30, 2022
(cherry picked from commit 367f552)

Co-authored-by: Christoph Anton Mitterer <calestyo@scientia.org>
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 3.11 3.12 easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants
X Tutup