bpo-38724: Implement subprocess.Popen.__repr__#17151
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
cool-RR
left a comment
There was a problem hiding this comment.
Thanks for working on this.
I think that the PID by itself is not useful enough for identifying what's going on. I'd suggest including the args (truncated if they're beyond a certain length) and the return code if the process is finished.
Also, tests.
|
@cool-RR Thanks for your review. Could you tell me where I can find the necessary value for length args (or where can I set variable for maximum length args)? |
cool-RR
left a comment
There was a problem hiding this comment.
Good work, I left a bunch of comments.
Thanks for your code review) |
taleinat
left a comment
There was a problem hiding this comment.
Thanks for the PR! It is certainly in the right direction :)
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @taleinat: please review the changes made to this pull request. |
taleinat
left a comment
There was a problem hiding this comment.
Thanks for making the changes so quickly!
This is in the right direction but I have a few more requests.
|
|
||
| return ( | ||
| f"<{self.__class__.__name__}: " | ||
| f"returncode:'{self.returncode}' args:'{args}'>" |
There was a problem hiding this comment.
I think the return code should not be surrounded by quotes: it will be either an integer or None, but never a string.
I'm not sure about args, but if we go with putting quotes around it, that would be interpreted as being a string literal, so we should use its repr, i.e. args:{args!r}.
There was a problem hiding this comment.
I agree regarding the return code.
Also regarding the args: I suggested map(shlex.quote, args) but I know there's also subprocess.list2cmdline which has different results. I picked the former arbitrarily, if you have reason to prefer the latter, go for it.
In any case, @dorosch should definitely remove the quotes he included and use !r as you suggested.
There was a problem hiding this comment.
Note that list2cmdline() is only for use on Windows!!
It may be wise to use it if _mswindows is true, falling back to ' '.join(map(shlex.quote, args)) otherwise.
Or just print the args as a list and avoid the whole issue:
f'<Popen: ... args: {list(self.args)!r}>There was a problem hiding this comment.
Note that
list2cmdline()is only for use on Windows!!
That was worth knowing! Thanks.
In that case, my recommendation is to stay with the shlex code that's in the PR. I'd avoid printing the args as a list, it's always annoying to see these lists when debugging. (Of course, they should always be used when calling subprocess functions.)
There was a problem hiding this comment.
Yes, command lines are easier to read when not written as lists. On the other hand, a list matches the interface of the Popen() constructor and the internal representation, is not platform-dependent, and is unambiguous.
It's a good sign that everything is settling down and we're left just with "bike-shedding" ;) The proper place for this discussion would be the bug tracker. Care to bring this up there, @cool-RR?
There was a problem hiding this comment.
Nah, it's indeed bikeshedding and we can let it go. After removing the shlex imports, this PR is good to go.
|
Thanks for making the requested changes! @taleinat: please review the changes made to this pull request. |
taleinat
left a comment
There was a problem hiding this comment.
Both of the shlex imports are no longer necessary.
Other than that, is LGTM!
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Thank you for your comment |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @taleinat: please review the changes made to this pull request. |
|
@gpshead, @giampaolo, want to take a look at this before it goes in? |
|
Thanks for the extra review @giampaolo! |
|
Also, thanks @cool-RR for the original suggestion and for the code reviews here! |
https://bugs.python.org/issue38724