Wrong documentation for PyUnicode_FromObject() (issue 15984)
Reviewers: , http://bugs.python.org/review/15984/diff/16922/Doc/c-api/unicode.rst File Doc/c-api/unicode.rst (right): http://bugs.python.org/review/15984/diff/16922/Doc/c-api/unicode.rst#newcode... Doc/c-api/unicode.rst:730: Copy a Unicode subtype object to a new base Unicode object if necessary. The term "base Unicode object" is not used anywhere else. The documentation for PyUnicode_Check() and PyUnicode_CheckExact() say just about a Unicode object and an instance of a Unicode subtype. Please review this at http://bugs.python.org/review/15984/ Affected files: Doc/c-api/unicode.rst Include/unicodeobject.h # HG changeset patch # Parent 4e186581fea7f82ce4688560e577d059eafccf01 diff -r 4e186581fea7 Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst Wed May 01 00:17:45 2013 +0200 +++ b/Doc/c-api/unicode.rst Sun Apr 10 04:09:49 2016 +0000 @@ -727,8 +727,11 @@ .. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj) - Shortcut for ``PyUnicode_FromEncodedObject(obj, NULL, "strict")`` which is used - throughout the interpreter whenever coercion to Unicode is needed. + Copy a Unicode subtype object to a new base Unicode object if necessary. + If *obj* is already a base Unicode object, return the reference with + incremented refcount. + + Objects other than Unicode or its subtypes will cause a :exc:`TypeError`. Locale Encoding diff -r 4e186581fea7 Include/unicodeobject.h --- a/Include/unicodeobject.h Wed May 01 00:17:45 2013 +0200 +++ b/Include/unicodeobject.h Sun Apr 10 04:09:49 2016 +0000 @@ -864,14 +864,11 @@ const char *errors /* error handling */ ); -/* Coerce obj to an Unicode object and return a reference with +/* Copy a Unicode subtype object to a new base Unicode object if necessary. + + If obj is already a base Unicode object, return the reference with *incremented* refcount. - Unicode objects are passed back as-is (subclasses are converted to - true Unicode objects), all other objects are delegated to - PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in - using UTF-8 encoding as basis for decoding the object. - The API returns NULL in case of an error. The caller is responsible for decref'ing the returned objects.
participants (1)
-
storchaka@gmail.com