diff -r cb2e3188832b Lib/_pyio.py --- a/Lib/_pyio.py Tue May 31 17:11:26 2011 -0500 +++ b/Lib/_pyio.py Tue May 31 20:56:12 2011 -0400 @@ -165,8 +165,8 @@ text = "t" in modes binary = "b" in modes if "U" in modes: - if writing or appending: - raise ValueError("can't use U and writing mode at once") + if writing or appending or updating: + raise ValueError("mode U cannot be combined with 'w', 'a', or '+'") reading = True if text and binary: raise ValueError("can't have text and binary mode at once") diff -r cb2e3188832b Lib/test/test_file.py --- a/Lib/test/test_file.py Tue May 31 17:11:26 2011 -0500 +++ b/Lib/test/test_file.py Tue May 31 20:56:12 2011 -0400 @@ -139,7 +139,7 @@ def testModeStrings(self): # check invalid mode strings - for mode in ("", "aU", "wU+"): + for mode in ("", "aU", "wU+", "U+", "+U", "rU+"): try: f = self.open(TESTFN, mode) except ValueError: diff -r cb2e3188832b Misc/NEWS --- a/Misc/NEWS Tue May 31 17:11:26 2011 -0500 +++ b/Misc/NEWS Tue May 31 20:56:12 2011 -0400 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #2091: open() accepted a 'U' mode string containing '+', but 'U' can + only be used with 'r'. + - Issue #12225: Still allow Python to build if Python is not in its hg repo or mercurial is not installed. diff -r cb2e3188832b Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Tue May 31 17:11:26 2011 -0500 +++ b/Modules/_io/_iomodule.c Tue May 31 20:56:12 2011 -0400 @@ -371,12 +371,11 @@ /* Parameters validation */ if (universal) { - if (writing || appending) { + if (writing || appending || updating) { PyErr_SetString(PyExc_ValueError, - "can't use U and writing mode at once"); + "mode U cannot be combined with 'w', 'a', or '+'"); return NULL; } - reading = 1; } if (text && binary) {