[New-bugs-announce] [issue12946] PyModule_GetDict() claims it can never fail, but it can

Stefan Behnel report at bugs.python.org
Fri Sep 9 18:19:52 CEST 2011


New submission from Stefan Behnel <scoder at users.sourceforge.net>:

As is obvious from the code, PyModule_GetDict() can fail if being passed a non-module object, and when the (unlikely) dict creation at the end fails. The documentation of the C-API function should be fixed to reflect that, i.e. it should state that NULL is returned in the case of an error.

PyObject *
PyModule_GetDict(PyObject *m)
{
    PyObject *d;
    if (!PyModule_Check(m)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    d = ((PyModuleObject *)m) -> md_dict;
    if (d == NULL)
        ((PyModuleObject *)m) -> md_dict = d = PyDict_New();
    return d;
}

----------
assignee: docs at python
components: Documentation
messages: 143764
nosy: docs at python, scoder
priority: normal
severity: normal
status: open
title: PyModule_GetDict() claims it can never fail, but it can
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12946>
_______________________________________


More information about the New-bugs-announce mailing list