Eryk Sun <eryk...@gmail.com> added the comment:

If a PathLike args value is supported in Windows, then it must be processed 
through list2cmdline, in case it needs to be quoted. Also, the preferred usage 
is to pass args as a list when shell is false. This common case shouldn't be 
penalized as a TypeError. Also, passing `executable` as PathLike should be 
supported, as is already the case in the POSIX implementation. For example.

_execute_child:

    if executable is not None and not isinstance(executable, str):
        executable = os.fsdecode(executable)

    if not isinstance(args, str):
        try:
            args = list2cmdline(args)
        except TypeError:
            if isinstance(args, bytes):
                args = os.fsdecode(args)
            elif isinstance(args, os.PathLike):
                args = list2cmdline([args])
            else:
                raise
        
list2cmdline should support PathLike arguments via os.fsdecode. This removes an 
existing inconsistency since the POSIX implementation converts args via 
PyUnicode_FSConverter in Modules/_posixsubprocess.c. For example:

list2cmdline:

    for arg in seq:
        if not isinstance(arg, str):
            arg = os.fsdecode(arg)

Finally, passing args as a string when shell is false can never be deprecated 
on Windows. list2cmdline works in most cases, but Windows CreateProcess takes a 
command line, and applications are free to parse the command line however they 
want. IMHO, the case that should be deprecated is passing args as a 
list/sequence when shell is true.

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31961>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to