Bug in os.path.ismount() or perhaps os.DirEntry()?

Hey.

I wonder whether the following is a bug in Python (using 3.10.6).

With this code:

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)

I get a:

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

I use the function with bytes (since pathnames are bytes),… p is a os.DirEntry (which is documented to support the PathLike-interface, as is os.path.ismount()).

So my expectation would have been, that I can use os.path.ismount(p) (which does work when I use strings) and it would still work.
However, I need to explicitly use os.path.ismount(p.path) for Python to realise that I want bytes.

Cheers,
Chris.

This is a bug in posixpath.ismount(). It uses the path argument without first converting to str or bytes via os.fspath().

Thanks, I’ll file it in the github.

For the records:

Thanks for the report and PR, @calestyo . A test addition will be helpful here to prevent regressions.