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

bpo-38724: Implement subprocess.Popen.__repr__ #17151

Merged
merged 9 commits into from Nov 17, 2019

Conversation

dorosch
Copy link
Contributor

@dorosch dorosch commented Nov 14, 2019

@dorosch dorosch requested a review from gpshead as a code owner Nov 14, 2019
@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Nov 14, 2019

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 username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@dorosch

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!

Copy link
Contributor

@cool-RR cool-RR left a 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.

@dorosch
Copy link
Contributor Author

dorosch commented Nov 14, 2019

@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)?

Copy link
Contributor

@cool-RR cool-RR left a comment

Good work, I left a bunch of comments.

Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/test/test_subprocess.py Outdated Show resolved Hide resolved
Lib/test/test_subprocess.py Outdated Show resolved Hide resolved
Lib/test/test_subprocess.py Outdated Show resolved Hide resolved
Lib/test/test_subprocess.py Outdated Show resolved Hide resolved
Copy link
Contributor

@cool-RR cool-RR left a comment

Looks good to me!

@dorosch
Copy link
Contributor Author

dorosch commented Nov 15, 2019

Looks good to me!

Thanks for your code review)

Copy link
Contributor

@taleinat taleinat left a comment

Thanks for the PR! It is certainly in the right direction :)

Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/subprocess.py Outdated Show resolved Hide resolved
Lib/test/test_subprocess.py Outdated Show resolved Hide resolved
Lib/subprocess.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

bedevere-bot commented Nov 15, 2019

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. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@dorosch
Copy link
Contributor Author

dorosch commented Nov 15, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

bedevere-bot commented Nov 15, 2019

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from taleinat Nov 15, 2019
@brandtbucher brandtbucher added the type-feature A feature request or enhancement label Nov 15, 2019
Copy link
Contributor

@taleinat taleinat left a comment

Thanks for making the changes so quickly!

This is in the right direction but I have a few more requests.

Lib/subprocess.py Outdated Show resolved Hide resolved

return (
f"<{self.__class__.__name__}: "
f"returncode:'{self.returncode}' args:'{args}'>"
Copy link
Contributor

@taleinat taleinat Nov 15, 2019

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}.

Copy link
Contributor

@cool-RR cool-RR Nov 15, 2019

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.

Copy link
Contributor

@taleinat taleinat Nov 15, 2019

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}>

Copy link
Contributor

@cool-RR cool-RR Nov 16, 2019

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.)

Copy link
Contributor

@taleinat taleinat Nov 16, 2019

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?

Copy link
Contributor

@cool-RR cool-RR Nov 17, 2019

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.

Lib/test/test_subprocess.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

bedevere-bot commented Nov 16, 2019

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from taleinat Nov 16, 2019
Copy link
Contributor

@taleinat taleinat left a comment

Both of the shlex imports are no longer necessary.

Other than that, is LGTM!

@bedevere-bot
Copy link

bedevere-bot commented Nov 16, 2019

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. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@dorosch
Copy link
Contributor Author

dorosch commented Nov 17, 2019

Both of the shlex imports are no longer necessary.

Other than that, is LGTM!

Thank you for your comment

@dorosch
Copy link
Contributor Author

dorosch commented Nov 17, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

bedevere-bot commented Nov 17, 2019

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from taleinat Nov 17, 2019
Copy link
Contributor

@taleinat taleinat left a comment

LGTM

@taleinat
Copy link
Contributor

taleinat commented Nov 17, 2019

@gpshead, @giampaolo, want to take a look at this before it goes in?

Copy link
Contributor

@giampaolo giampaolo left a comment

LGTM. Good change.

@taleinat
Copy link
Contributor

taleinat commented Nov 17, 2019

Thanks for the extra review @giampaolo!

@taleinat taleinat merged commit 645005e into python:master Nov 17, 2019
@taleinat
Copy link
Contributor

taleinat commented Nov 17, 2019

Also, thanks @cool-RR for the original suggestion and for the code reviews here!

jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants