From 763c24c3b278c133cb87f63a4beb93d5e1c313f5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 10 Dec 2018 12:40:19 +0200 Subject: [PATCH 1/2] bpo-35452: Make PySys_HasWarnOptions() never raising an exception. --- Python/sysmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e6f1c4e8e9e0c0..2b7820aa7030af 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1845,7 +1845,8 @@ int PySys_HasWarnOptions(void) { PyObject *warnoptions = _PySys_GetObjectId(&PyId_warnoptions); - return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0; + return (warnoptions != NULL && PyList_Check(warnoptions) + && PyList_GET_SIZE(warnoptions)); } static PyObject * From 3fc23d5ed70e55421cfefba4777e472cad5f0fe6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 10 Dec 2018 12:53:19 +0200 Subject: [PATCH 2/2] Update Python/sysmodule.c Co-Authored-By: serhiy-storchaka --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 2b7820aa7030af..029de2d5ae7fa1 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1846,7 +1846,7 @@ PySys_HasWarnOptions(void) { PyObject *warnoptions = _PySys_GetObjectId(&PyId_warnoptions); return (warnoptions != NULL && PyList_Check(warnoptions) - && PyList_GET_SIZE(warnoptions)); + && PyList_GET_SIZE(warnoptions) > 0); } static PyObject *