Message401301
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'" |
|
Date |
User |
Action |
Args |
2021-09-07 16:27:33 | alexia | set | recipients:
+ alexia |
2021-09-07 16:27:33 | alexia | set | messageid: <1631032053.23.0.444664437221.issue45130@roundup.psfhosted.org> |
2021-09-07 16:27:33 | alexia | link | issue45130 messages |
2021-09-07 16:27:33 | alexia | create | |
|