[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-27 Thread STINNER Victor

STINNER Victor added the comment:

For all reasons alread given in the previous comment and my comment below, I 
reject the proposed change.


Serhiy> See also issue26748. Classes usually have True boolean value, but empty 
enum classes were False-y by accident. This was considered a bug.

Another example: issue #13936, "RFE: change bool(datetime.time(0, 0, 0)) to 
evaluate as True". datetime.time was changed in Python 3.5 to always be true, 
especially for the time 00:00:00. It's the opposite of the proposed change for 
CompletedProcess.


The problem is also that different users can expect a different answer from 
bool(CompletedProcess): non-zero return code, non-empty stdout, empty stderr, 
etc.

CompleteProcess is a complex object with many attributes, it's not as simple as 
a tuple or a string, where the truthness is obvious.


> Richard Neumann: "A useless use case is attached."

"if subprocess.run(...):"

Sorry, I'm not convinced that the need of breaking the backward compatibility 
for this "useless use case". It's trivial to split it in two lines:

"cmd = subprocess.run(...); if cmd.returncode: (...)"

By the way, it became common that I write such code, and in this case, I need 
the returncode value in the if block:

"cmd = subprocess.run(...); if cmd.returncode: sys.exit(cmd.returncode)".

So I need the CompletedProcess object anyway.

--
resolution:  -> rejected
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-27 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

See also issue26748. Classes usually have True boolean value, but empty enum 
classes were False-y by accident. This was considered a bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-27 Thread Raymond Hettinger

Raymond Hettinger added the comment:

> The change can break existing code that uses boolean testing 
> instead of checking for None.

For this reason, I think Guido would oppose this proposal.  In the past he has 
objected to iterators having a True boolean value to indicate that there were 
more values available for iteration.  I think similar reasoning applies here.

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I'm not sure that it is worth to implement the __bool__() method. This doesn't 
add much in comparison with checking the returncode attribute.

The change can break existing code that uses boolean testing instead of 
checking for None.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-26 Thread Sayan Chowdhury

Changes by Sayan Chowdhury :


--
pull_requests: +273

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-18 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
versions: +Python 3.7 -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2017-02-18 Thread Sayan Chowdhury

Sayan Chowdhury added the comment:

I am taking over to do the rest part required for this ticket.

--
nosy: +sayanchowdhury

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2016-05-12 Thread Richard Neumann

Richard Neumann added the comment:

Thank you for the hint.
I never before contributed code to the python foundation and thus am not 
familiar with the process.
I will look into it when I find the time.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2016-05-12 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This is not enough. New feature should be documented (in new method docstring, 
in subprocess documentation and in What's New document) and tested.

And please sign a Contributor Licensing Agreement.

http://www.python.org/psf/contrib/contrib-form/
http://www.python.org/psf/contrib/

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2016-05-12 Thread Richard Neumann

Richard Neumann added the comment:

Please excuse my ambiguous phrasing.
What I meant was I created the patch _from_ the Python 3.5.1 module _for_ 
Python 3.6.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2016-05-12 Thread STINNER Victor

STINNER Victor added the comment:

It's a new feature, it should only go to Python 3.6.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2016-05-12 Thread Richard Neumann

Richard Neumann added the comment:

I took the liberty to create a patch for Python v3.5.1.

--
keywords: +patch
nosy: +Richard Neumann
Added file: http://bugs.python.org/file42828/subprocess.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2016-04-26 Thread Berker Peksag

Berker Peksag added the comment:

The idea sounds good to me.

--
nosy: +berker.peksag
stage:  -> needs patch
versions: +Python 3.6 -Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2015-10-22 Thread STINNER Victor

STINNER Victor added the comment:

Can you please give examples of use cases? (code)

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2015-10-22 Thread Richard Neumann

Richard Neumann added the comment:

A useless use case is attached.
Basically it boils down to having the ability to evaluate the CompletedProcess 
directly by if/else rather than comparing its returncode attribute to zero each 
time or handling the exception raised by check_returncode().
I use this quite frequently in programs which run system commands.
Before the new subprocess.run() method and subprocess.CompletedProcess were 
introduced with python 3.5 I already wrote my own library for that, wich now 
nearly became obsoleted by the new subprocess library of python 3.5 with the 
expection that it does not have this feature.
See the class ProcessResult here: 
https://github.com/HOMEINFO/homeinfo-lib/blob/master/homeinfo/lib/system.py

--
Added file: http://bugs.python.org/file40836/usecase.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25452] Add __bool__() method to subprocess.CompletedProcess

2015-10-21 Thread Richard Neumann

New submission from Richard Neumann:

The class subprocess.CompletedProcess is currently lacking a __bool__() method.

It might be a practical feature to have the possibility to evaluate a 
CompletedProcess instance in an if/else block without the necessity to handle 
the exception raised by CompletedProcess.check_returncode().

Hence, I suggest adding the method

def __bool__(self):
return self.returncode == 0

to the class.

--
components: Library (Lib)
messages: 253282
nosy: conqp
priority: normal
severity: normal
status: open
title: Add __bool__() method to subprocess.CompletedProcess
type: enhancement
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com