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

Accept path-like arguments in shlex.join() #132194

Open
FFY00 opened this issue Apr 7, 2025 · 4 comments
Open

Accept path-like arguments in shlex.join() #132194

FFY00 opened this issue Apr 7, 2025 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@FFY00
Copy link
Member

FFY00 commented Apr 7, 2025

Feature or enhancement

Proposal:

A common use-case of shlex.join is to get a shell-like invocation of a command.

In my experience, when writing small custom scripts, it is very common to use shlex.join in conjunction with subprocess.run, to log the command invocation to the output. subprocess.run has accepted path-like arguments since 3.6 on POSIX, and 3.8 on Windows, so when we want to use shutil.join, we need extra code to convert the path-like objects in the command sequence to strings.

It would be nice if shutil.join could receive the same command sequence as subprocess.run.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

GH-72809 proposed this for shlex.quote.

@FFY00 FFY00 added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Apr 7, 2025
@picnixz
Copy link
Member

picnixz commented Apr 7, 2025

If shlex.quote already accepts path-like objects, then it ought to be better if shlex.join does so as well.

EDIT: The feature was rejected for shlex.quote actually!

@FFY00
Copy link
Member Author

FFY00 commented Apr 7, 2025

It doesn't, the proposal was rejected.

@picnixz
Copy link
Member

picnixz commented Apr 7, 2025

Yes, I actually didn't read the other issue entirely as it was marked as completed and not "not planned"!

I think the argument of "shlex.quote() takes a string, not a path (semantically)" also apply here then. shlex.join() joins shell arguments, not path components. Wouldn't shlex.join(map(str, split_command)) be sufficient?

@picnixz
Copy link
Member

picnixz commented Apr 7, 2025

While I can guess why subprocess.run() accepts path-like objects, shlex.join is (semantically) dedicated to lexical analysis. So... I'm rather -0 on this. What was the rationale for accepting path-like objects in subprocess.run()?

See #76142 for the rationale for subprocess.run(). There was still a long discussion that I haven't read yet though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants