diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2012-10-09 12:28:10 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2012-10-09 12:28:10 (GMT) |
commit | ea69bd3ce14a776be0a64e32d45a3ee60d91210a (patch) | |
tree | 925775eb61f3a4695a4ca93399521a1f227bf2bb | |
parent | 38714d64d0125dea543dcb63e3152d2f0836e558 (diff) | |
download | cpython-ea69bd3ce14a776be0a64e32d45a3ee60d91210a.zip cpython-ea69bd3ce14a776be0a64e32d45a3ee60d91210a.tar.gz cpython-ea69bd3ce14a776be0a64e32d45a3ee60d91210a.tar.bz2 |
Issue #16169: Fix ctypes.WinError()'s confusion between errno and winerror
-rw-r--r-- | Lib/ctypes/__init__.py | 2 | ||||
-rw-r--r-- | Lib/ctypes/test/test_win32.py | 22 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 25 insertions, 1 deletions
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index f0bd66a..c92e130 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -456,7 +456,7 @@ if _os.name in ("nt", "ce"): code = GetLastError() if descr is None: descr = FormatError(code).strip() - return WindowsError(code, descr) + return WindowsError(None, descr, None, code) if sizeof(c_uint) == sizeof(c_void_p): c_size_t = c_uint diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py index 2534a74..128914e 100644 --- a/Lib/ctypes/test/test_win32.py +++ b/Lib/ctypes/test/test_win32.py @@ -67,6 +67,28 @@ if sys.platform == "win32": self.assertEqual(ex.text, "text") self.assertEqual(ex.details, ("details",)) + class TestWinError(unittest.TestCase): + def test_winerror(self): + # see Issue 16169 + import errno + ERROR_INVALID_PARAMETER = 87 + msg = FormatError(ERROR_INVALID_PARAMETER).strip() + args = (errno.EINVAL, msg, None, ERROR_INVALID_PARAMETER) + + e = WinError(ERROR_INVALID_PARAMETER) + self.assertEqual(e.args, args) + self.assertEqual(e.errno, errno.EINVAL) + self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER) + + windll.kernel32.SetLastError(ERROR_INVALID_PARAMETER) + try: + raise WinError() + except OSError as exc: + e = exc + self.assertEqual(e.args, args) + self.assertEqual(e.errno, errno.EINVAL) + self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER) + class Structures(unittest.TestCase): def test_struct_by_value(self): @@ -37,6 +37,8 @@ Core and Builtins Library ------- +- Issue #16169: Fix ctypes.WinError()'s confusion between errno and winerror. + - Issue #16089: Allow ElementTree.TreeBuilder to work again with a non-Element element_factory (fixes a regression in SimpleTAL). |