1-
21/* System module */
32
43/*
@@ -75,15 +74,20 @@ module sys
7574#include "clinic/sysmodule.c.h"
7675
7776
78- #define WarnIncomingSysAbiflagsChange () \
79- PyErr_WarnEx(PyExc_DeprecationWarning, \
80- "sys.abiflags will be set to a meaningful value on all platforms " \
81- "in Python 3.16 instead of absent.\n\n" \
82- "Please consider using `warnings.simplefilter()` with the " \
83- "`warnings.catch_warnings()` context manager.\n" \
84- "Or update the code with `if sys.platform.startswith('win')` condition.", \
85- /*stack_level=*/ 1 )
86-
77+ // XXX: remove this and related code after set sys.abiflags on Windows in 3.16.
78+ static int
79+ _warn_incoming_sys_abiflags_change ()
80+ {
81+ return PyErr_WarnEx (
82+ PyExc_DeprecationWarning ,
83+ "sys.abiflags will be set to a meaningful value on all platforms "
84+ "in Python 3.16 instead of absent.\n\n"
85+ "Please consider using `warnings.simplefilter()` with the "
86+ "`warnings.catch_warnings()` context manager.\n"
87+ "Or update the code with `if sys.platform.startswith('win')` "
88+ "condition." ,
89+ /*stack_level=*/ 1 );
90+ }
8791
8892PyObject *
8993_PySys_GetRequiredAttr (PyObject * name )
@@ -104,7 +108,8 @@ _PySys_GetRequiredAttr(PyObject *name)
104108 if (PyDict_GetItemRef (sysdict , name , & value ) == 0 ) {
105109#ifndef ABIFLAGS
106110 if (_PyUnicode_EqualToASCIIString (name , "abiflags" )) {
107- if (WarnIncomingSysAbiflagsChange () < 0 ) {
111+ if (_warn_incoming_sys_abiflags_change () < 0 ) {
112+ Py_XDECREF (value );
108113 return NULL ;
109114 }
110115 }
@@ -127,7 +132,8 @@ _PySys_GetRequiredAttrString(const char *name)
127132 if (PyDict_GetItemStringRef (sysdict , name , & value ) == 0 ) {
128133#ifndef ABIFLAGS
129134 if (strcmp (name , "abiflags" ) == 0 ) {
130- if (WarnIncomingSysAbiflagsChange () < 0 ) {
135+ if (_warn_incoming_sys_abiflags_change () < 0 ) {
136+ Py_XDECREF (value );
131137 return NULL ;
132138 }
133139 }
@@ -156,7 +162,7 @@ _PySys_GetOptionalAttr(PyObject *name, PyObject **value)
156162 int ret = PyDict_GetItemRef (sysdict , name , value );
157163#ifndef ABIFLAGS
158164 if (ret == 0 && _PyUnicode_EqualToASCIIString (name , "abiflags" )) {
159- if (WarnIncomingSysAbiflagsChange () < 0 ) {
165+ if (_warn_incoming_sys_abiflags_change () < 0 ) {
160166 return -1 ;
161167 }
162168 }
@@ -176,7 +182,7 @@ _PySys_GetOptionalAttrString(const char *name, PyObject **value)
176182 int ret = PyDict_GetItemStringRef (sysdict , name , value );
177183#ifndef ABIFLAGS
178184 if (ret == 0 && strcmp (name , "abiflags" ) == 0 ) {
179- if (WarnIncomingSysAbiflagsChange () < 0 ) {
185+ if (_warn_incoming_sys_abiflags_change () < 0 ) {
180186 return -1 ;
181187 }
182188 }
@@ -204,7 +210,7 @@ PySys_GetObject(const char *name)
204210 Py_XDECREF (value ); // return a borrowed reference
205211#ifndef ABIFLAGS
206212 if (ret == 0 && strcmp (name , "abiflags" ) == 0 ) {
207- if (WarnIncomingSysAbiflagsChange () < 0 ) {
213+ if (_warn_incoming_sys_abiflags_change () < 0 ) {
208214 return NULL ;
209215 }
210216 }
@@ -978,16 +984,18 @@ sys___getattr__(PyObject *module, PyObject *name)
978984{
979985 PyObject * value = NULL ;
980986 if (_PySys_GetOptionalAttr (name , & value ) < 0 ) {
987+ Py_XDECREF (value );
981988 return NULL ;
982989 }
983990 if (value == NULL ) {
991+ PyErr_Clear ();
984992 PyErr_Format (PyExc_AttributeError ,
985993 "module 'sys' has no attribute '%U'" , name );
986994 }
987995 return value ;
988996}
989997
990- PyDoc_STRVAR (__getattr___doc ,
998+ PyDoc_STRVAR (sysmodule__getattr___doc ,
991999"__getattr__($module, name, /)\n"
9921000"--\n"
9931001"\n"
@@ -2726,7 +2734,7 @@ static PyMethodDef sys_methods[] = {
27262734 SYS_EXCEPTHOOK_METHODDEF
27272735 SYS_EXIT_METHODDEF
27282736 {"__getattr__ ", _PyCFunction_CAST (sys___getattr__ ),
2729- METH_O , __getattr___doc },
2737+ METH_O , sysmodule__getattr___doc },
27302738 SYS_GETDEFAULTENCODING_METHODDEF
27312739 SYS_GETDLOPENFLAGS_METHODDEF
27322740 SYS_GETALLOCATEDBLOCKS_METHODDEF
0 commit comments