Index: Objects/fileobject.c =================================================================== --- Objects/fileobject.c (revision 61453) +++ Objects/fileobject.c (working copy) @@ -155,7 +155,7 @@ if (upos) { memmove(upos, upos+1, len-(upos-mode)); /* incl null char */ - if (mode[0] == 'w' || mode[0] == 'a') { + if (mode[0] == 'w' || mode[0] == 'a' || strchr(mode, '+')) { PyErr_Format(PyExc_ValueError, "universal newline " "mode can only be used with modes " "starting with 'r'"); @@ -2075,7 +2075,7 @@ "the value for this attribute is one of None (no newline read yet),\n" "'\\r', '\\n', '\\r\\n' or a tuple containing all the newline types seen.\n" "\n" -"'U' cannot be combined with 'w' or '+' mode.\n" +"'U' cannot be combined with 'w', 'a', or '+' mode.\n" ); PyTypeObject PyFile_Type = { Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 61453) +++ Misc/NEWS (working copy) @@ -12,6 +12,9 @@ Core and builtins ----------------- +- Issue #2091: file() accepted a 'U' mode string containing '+', but 'U' can + only be used with 'r'. + - Issue #1779871: Gnu gcc can now build Python on OS X because the flags -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd are no longer passed. Index: Lib/test/test_file.py =================================================================== --- Lib/test/test_file.py (revision 61453) +++ Lib/test/test_file.py (working copy) @@ -121,7 +121,7 @@ def testModeStrings(self): # check invalid mode strings - for mode in ("", "aU", "wU+"): + for mode in ("", "aU", "wU", "U+", "+U", "rU+"): try: f = open(TESTFN, mode) except ValueError: