From e3d09ff269330bd0076e3ab9cb81907fad717a68 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Tue, 15 Mar 2011 17:41:13 -0400 Subject: #11216: document all possible set_charset execution paths. --- Doc/library/email.message.rst | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Doc/library/email.message.rst b/Doc/library/email.message.rst index d1a12c5..4b23f6a 100644 --- a/Doc/library/email.message.rst +++ b/Doc/library/email.message.rst @@ -130,15 +130,22 @@ Here are the methods of the :class:`Message` class: string naming a character set, or ``None``. If it is a string, it will be converted to a :class:`~email.charset.Charset` instance. If *charset* is ``None``, the ``charset`` parameter will be removed from the - :mailheader:`Content-Type` header. Anything else will generate a - :exc:`TypeError`. - - The message will be assumed to be of type :mimetype:`text/\*` encoded with - *charset.input_charset*. It will be converted to *charset.output_charset* - and encoded properly, if needed, when generating the plain text - representation of the message. MIME headers (:mailheader:`MIME-Version`, - :mailheader:`Content-Type`, :mailheader:`Content-Transfer-Encoding`) will - be added as needed. + :mailheader:`Content-Type` header (the message will not be otherwise + modified). Anything else will generate a :exc:`TypeError`. + + If there is no existing :mailheader:`MIME-Version` header one will be + added. If there is no existing :mailheader:`Content-Type` header, one + will be added with a value of :mimetype:`text/plain`. Whether the + :mailheader:`Content-Type` header already exists or not, its ``charset`` + parameter will be set to *charset.output_charset*. If + *charset.input_charset* and *charset.output_charset* differ, the payload + will be re-encoded to the *output_charset*. If there is no existing + :mailheader:`Content-Transfer-Encoding` header, then the payload will be + transfer-encoded, if needed, using the specified + :class:`~email.charset.Charset`, and a header with the appropriate value + will be added. If a :mailheader:`Content-Transfer-Encoding` header + already exists, the payload is assumed to already be correctly encoded + using that :mailheader:`Content-Transfer-Encoding` and is not modified. .. method:: get_charset() -- cgit v0.12 From 29dcaad6eb47d27fc2d450ae6d81cdf1d740be38 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 14:50:16 -0700 Subject: Issue 11510: Fix BUILD_SET optimizer bug. --- Lib/test/test_peepholer.py | 14 +++++++++++++- Misc/NEWS | 2 ++ Python/peephole.c | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 531b425..b7d446f 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -267,11 +267,23 @@ class TestTranforms(unittest.TestCase): asm = disassemble(f) self.assertNotIn('BINARY_ADD', asm) +class TestBuglets(unittest.TestCase): + + def test_bug_11510(self): + # folded constant set optimization was commingled with the tuple + # unpacking optimization which would fail if the set had duplicate + # elements so that the set length was unexpected + def f(): + x, y = {1, 1} + return x, y + with self.assertRaises(ValueError): + f() + def test_main(verbose=None): import sys from test import support - test_classes = (TestTranforms,) + test_classes = (TestTranforms, TestBuglets) support.run_unittest(*test_classes) # verify reference counting diff --git a/Misc/NEWS b/Misc/NEWS index 8b72498..42330ff 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.2.1? Core and Builtins ----------------- +- Issue #11510: Fixed optimizer bug which turned "a,b={1,1}" into "a,b=(1,1)". + - Issue #11432: A bug was introduced in subprocess.Popen on posix systems with 3.2.0 where the stdout or stderr file descriptor being the same as the stdin file descriptor would raise an exception. webbrowser.open would fail. fixed. diff --git a/Python/peephole.c b/Python/peephole.c index f972e16..6985043 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -475,7 +475,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, } if (codestr[i+3] != UNPACK_SEQUENCE || !ISBASICBLOCK(blocks,i,6) || - j != GETARG(codestr, i+3)) + j != GETARG(codestr, i+3) || + opcode == BUILD_SET) continue; if (j == 1) { memset(codestr+i, NOP, 6); -- cgit v0.12 From 0661e91feda0757c10c8b3bf3fa047b7d3e50444 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 15:03:36 -0700 Subject: Issue 11510: Fix BUILD_SET optimizer bug. --- Lib/test/test_peepholer.py | 14 +++++++++++++- Python/peephole.c | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index a9eb23f..a40b4b7 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -294,11 +294,23 @@ class TestTranforms(unittest.TestCase): self.assertNotIn('BINARY_', asm, e) self.assertNotIn('BUILD_', asm, e) +class TestBuglets(unittest.TestCase): + + def test_bug_11510(self): + # folded constant set optimization was commingled with the tuple + # unpacking optimization which would fail if the set had duplicate + # elements so that the set length was unexpected + def f(): + x, y = {1, 1} + return x, y + with self.assertRaises(ValueError): + f() + def test_main(verbose=None): import sys from test import support - test_classes = (TestTranforms,) + test_classes = (TestTranforms, TestBuglets) support.run_unittest(*test_classes) # verify reference counting diff --git a/Python/peephole.c b/Python/peephole.c index ab96ce9..4bc65dc 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -535,7 +535,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, } if (codestr[i+3] != UNPACK_SEQUENCE || !ISBASICBLOCK(blocks,i,6) || - j != GETARG(codestr, i+3)) + j != GETARG(codestr, i+3) || + opcode == BUILD_SET) continue; if (j == 1) { memset(codestr+i, NOP, 6); -- cgit v0.12 From f932f747e6242c7de88864798e845135d9d981c9 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 15:06:09 -0700 Subject: whitespace fix --- Lib/test/test_peepholer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index a40b4b7..bab4c1e 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -19,6 +19,7 @@ def disassemble(func): def dis_single(line): return disassemble(compile(line, '', 'single')) + class TestTranforms(unittest.TestCase): def test_unot(self): -- cgit v0.12 From 5bd75b87263bc6502753381138e15531ce4574a6 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 15:07:38 -0700 Subject: whitespace fix --- Lib/test/test_peepholer.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index bab4c1e..f73565e 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -297,15 +297,15 @@ class TestTranforms(unittest.TestCase): class TestBuglets(unittest.TestCase): - def test_bug_11510(self): - # folded constant set optimization was commingled with the tuple - # unpacking optimization which would fail if the set had duplicate - # elements so that the set length was unexpected - def f(): - x, y = {1, 1} - return x, y - with self.assertRaises(ValueError): - f() + def test_bug_11510(self): + # folded constant set optimization was commingled with the tuple + # unpacking optimization which would fail if the set had duplicate + # elements so that the set length was unexpected + def f(): + x, y = {1, 1} + return x, y + with self.assertRaises(ValueError): + f() def test_main(verbose=None): -- cgit v0.12 From c867239a3121a51102d99c9bc1dbdf30566b0cbe Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Tue, 15 Mar 2011 18:19:58 -0400 Subject: Wing project file update for mercurial --- .hgignore | 1 + Misc/python-wing4.wpr | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.hgignore b/.hgignore index d3983dc..70aca54 100644 --- a/.hgignore +++ b/.hgignore @@ -50,6 +50,7 @@ libpython*.a *~ Lib/lib2to3/*.pickle Lib/test/data/* +Misc/*.wpu PC/python_nt*.h PC/pythonnt_rc*.h PC/*.obj diff --git a/Misc/python-wing4.wpr b/Misc/python-wing4.wpr index 795b694..7adfdbd 100644 --- a/Misc/python-wing4.wpr +++ b/Misc/python-wing4.wpr @@ -5,11 +5,12 @@ ################################################################## [project attributes] proj.directory-list = [{'dirloc': loc('..'), - 'excludes': [u'Lib/unittest/test/__pycache__', - u'Lib/__pycache__', - u'Doc/build', + 'excludes': [u'.hg', u'Lib/unittest/__pycache__', - u'build'], + u'Lib/unittest/test/__pycache__', + u'Lib/__pycache__', + u'build', + u'Doc/build'], 'filter': '*', 'include_hidden': False, 'recursive': True, -- cgit v0.12