[Python-checkins] cpython (2.7): Close #12085: Fix an attribute error in subprocess.Popen destructor if the

victor.stinner python-checkins at python.org
Wed Jun 1 01:08:56 CEST 2011


http://hg.python.org/cpython/rev/26ea0a46aadd
changeset: 70556:26ea0a46aadd
branch: 2.7
parent: 70540:6c6923a406df
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Wed Jun 01 01:03:00 2011 +0200
summary:
 Close #12085: Fix an attribute error in subprocess.Popen destructor if the
constructor has failed, e.g. because of an undeclared keyword argument. Patch
written by Oleg Oshmyan.
files:
 Lib/subprocess.py | 5 ++++-
 Lib/test/test_subprocess.py | 10 ++++++++++
 Misc/ACKS | 1 +
 Misc/NEWS | 4 ++++
 4 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -707,7 +707,10 @@
 
 
 def __del__(self, _maxint=sys.maxint, _active=_active):
- if not self._child_created:
+ # If __init__ hasn't had a chance to execute (e.g. if it
+ # was passed an undeclared keyword argument), we don't
+ # have a _child_created attribute at all.
+ if not getattr(self, '_child_created', False):
 # We didn't get to successfully create a child process.
 return
 # In case the child hasn't been waited on, check if it's done.
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -113,6 +113,16 @@
 env=newenv)
 self.assertEqual(rc, 1)
 
+ def test_invalid_args(self):
+ # Popen() called with invalid arguments should raise TypeError
+ # but Popen.__del__ should not complain (issue #12085)
+ with support.captured_stderr() as s:
+ self.assertRaises(TypeError, subprocess.Popen, invalid_arg_name=1)
+ argcount = subprocess.Popen.__init__.__code__.co_argcount
+ too_many_args = [0] * (argcount + 1)
+ self.assertRaises(TypeError, subprocess.Popen, *too_many_args)
+ self.assertEqual(s.getvalue(), '')
+
 def test_stdin_none(self):
 # .stdin is None when not redirected
 p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -607,6 +607,7 @@
 Jason Orendorff
 Douglas Orr
 Michele Orrù
+Oleg Oshmyan
 Denis S. Otkidach
 Michael Otteneder
 R. M. Oudkerk
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,10 @@
 Library
 -------
 
+- Issue #12085: Fix an attribute error in subprocess.Popen destructor if the
+ constructor has failed, e.g. because of an undeclared keyword argument. Patch
+ written by Oleg Oshmyan.
+
 Tests
 -----
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /