New submission from Richard <nyuszik...@gmail.com>:
When one of the items in the iterable passed to shlex.join() is a pathlib.Path object, it throws an exception saying it must be str or bytes. I believe it should accept Path objects just like other parts of the standard library such as subprocess.run() already do. Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import shlex >>> from pathlib import Path >>> shlex.join(['foo', Path('bar baz')]) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.9/shlex.py", line 320, in join return ' '.join(quote(arg) for arg in split_command) File "/usr/lib/python3.9/shlex.py", line 320, in <genexpr> return ' '.join(quote(arg) for arg in split_command) File "/usr/lib/python3.9/shlex.py", line 329, in quote if _find_unsafe(s) is None: TypeError: expected string or bytes-like object >>> shlex.join(['foo', str(Path('bar baz'))]) "foo 'bar baz'" Python 3.11.0a0 (heads/main:fa15df77f0, Sep 7 2021, 18:22:35) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import shlex >>> from pathlib import Path >>> shlex.join(['foo', Path('bar baz')]) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/nyuszika7h/.pyenv/versions/3.11-dev/lib/python3.11/shlex.py", line 320, in join return ' '.join(quote(arg) for arg in split_command) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/nyuszika7h/.pyenv/versions/3.11-dev/lib/python3.11/shlex.py", line 320, in <genexpr> return ' '.join(quote(arg) for arg in split_command) ^^^^^^^^^^ File "/home/nyuszika7h/.pyenv/versions/3.11-dev/lib/python3.11/shlex.py", line 329, in quote if _find_unsafe(s) is None: ^^^^^^^^^^^^^^^ TypeError: expected string or bytes-like object, got 'PosixPath' >>> shlex.join(['foo', str(Path('bar baz'))]) "foo 'bar baz'" ---------- components: Library (Lib) messages: 401301 nosy: nyuszika7h priority: normal severity: normal status: open title: shlex.join() does not accept pathlib.Path objects type: behavior versions: Python 3.10, Python 3.11, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45130> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com