Skip to content

Commit 154a82a

Browse files
Address review comments.
1 parent 93ab31b commit 154a82a

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

Doc/c-api/sys.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ accessible to C code. They all work with the current interpreter thread's
260260
261261
.. c:function:: PyObject *PySys_GetAttr(PyObject *name)
262262
263-
Get the attribute *name* of the :mod:`sys` module. Return a :term:`strong reference`.
264-
Raise :exc:`RuntimeError` and return ``NULL`` if it does not exist.
263+
Get the attribute *name* of the :mod:`sys` module.
264+
Return a :term:`strong reference`.
265+
Raise :exc:`RuntimeError` and return ``NULL`` if it does not exist or
266+
if the :mod:`sys` module cannot be found.
265267
266268
If the non-existing object should not be treated as a failure, you can use
267269
:c:func:`PySys_GetOptionalAttr` instead.
@@ -279,21 +281,21 @@ accessible to C code. They all work with the current interpreter thread's
279281
280282
.. versionadded:: next
281283
282-
.. c:function:: int PySys_GetOptionalAttr(PyObject *name, PyObject **result);
284+
.. c:function:: int PySys_GetOptionalAttr(PyObject *name, PyObject **result)
283285
284286
Variant of :c:func:`PySys_GetAttr` which doesn't raise
285287
exception if the object does not exist.
286288
287-
If the object exists, set *\*result* to a new :term:`strong reference`
288-
to the object and return ``1``.
289-
If the object does not exist, set *\*result* to ``NULL`` and return ``0``,
290-
without setting an exception.
291-
If other error occurred, set an exception, set *\*result* to ``NULL`` and
292-
return ``-1``.
289+
* Set *\*result* to a new :term:`strong reference` to the object and
290+
return ``1`` if the object exists.
291+
* Set *\*result* to ``NULL`` and return ``0`` without setting an exception
292+
if the object does not exist.
293+
* Set an exception, set *\*result* to ``NULL``, and return ``-1``,
294+
if an error occurred.
293295
294296
.. versionadded:: next
295297
296-
.. c:function:: int PySys_GetOptionalAttrString(const char *name, PyObject **result);
298+
.. c:function:: int PySys_GetOptionalAttrString(const char *name, PyObject **result)
297299
298300
This is the same as :c:func:`PySys_GetOptionalAttr`, but *name* is
299301
specified as a :c:expr:`const char*` UTF-8 encoded bytes string,

Include/cpython/sysmodule.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

Python/sysmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ PySys_GetAttr(PyObject *name)
8080
{
8181
if (!PyUnicode_Check(name)) {
8282
PyErr_Format(PyExc_TypeError,
83-
"attribute name must be string, not '%.200s'",
84-
Py_TYPE(name)->tp_name);
83+
"attribute name must be string, not '%T'",
84+
name);
8585
return NULL;
8686
}
8787
PyThreadState *tstate = _PyThreadState_GET();
@@ -118,8 +118,8 @@ PySys_GetOptionalAttr(PyObject *name, PyObject **value)
118118
{
119119
if (!PyUnicode_Check(name)) {
120120
PyErr_Format(PyExc_TypeError,
121-
"attribute name must be string, not '%.200s'",
122-
Py_TYPE(name)->tp_name);
121+
"attribute name must be string, not '%T'",
122+
name);
123123
*value = NULL;
124124
return -1;
125125
}

0 commit comments

Comments
 (0)