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
bpo-38724: Implement subprocess.Popen.__repr__ #17151
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 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)? |
Thanks for your code review) |
Misc/NEWS.d/next/Library/2019-11-14-14-13-29.bpo-38724.T5ySfR.rst
Outdated
Show resolved
Hide resolved
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. |
Lib/subprocess.py
Outdated
|
||
return ( | ||
f"<{self.__class__.__name__}: " | ||
f"returncode:'{self.returncode}' args:'{args}'>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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