@@ -2671,6 +2671,11 @@ SimpleExtendsException(PyExc_ValueError, UnicodeError,
26712671/*
26722672 * Check the validity of 'attr' as a unicode or bytes object depending
26732673 * on 'as_bytes' and return a new reference on it if it is the case.
2674+ *
2675+ * The 'name' is the attribute name and is only used for error reporting.
2676+ *
2677+ * On success, this returns a strong reference on 'attr'.
2678+ * On failure, this sets an exception and returns NULL.
26742679 */
26752680static PyObject *
26762681as_unicode_error_attribute (PyObject * attr , const char * name , int as_bytes )
@@ -2702,6 +2707,12 @@ as_unicode_error_attribute(PyObject *attr, const char *name, int as_bytes)
27022707#define Py_UNICODE_TRANSLATE_ERROR_NAME "UnicodeTranslateError"
27032708
27042709
2710+ /*
2711+ * Check that 'self' is of a Unicode Error object.
2712+ *
2713+ * On success, this returns 0.
2714+ * On failure, this sets a TypeError exception and returns -1.
2715+ */
27052716static inline int
27062717check_unicode_error_type (PyObject * self , const char * expect_type )
27072718{
@@ -2717,7 +2728,8 @@ check_unicode_error_type(PyObject *self, const char *expect_type)
27172728/*
27182729 * Return the underlying (str) 'encoding' attribute of a Unicode Error object.
27192730 *
2720- * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject.
2731+ * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject,
2732+ * although this condition is verified by this function on DEBUG builds.
27212733 */
27222734static inline PyObject *
27232735unicode_error_get_encoding_impl (PyObject * self )
@@ -2731,7 +2743,8 @@ unicode_error_get_encoding_impl(PyObject *self)
27312743 * Return the underlying 'object' attribute of a Unicode Error object
27322744 * as a bytes or a string instance, depending on the 'as_bytes' flag.
27332745 *
2734- * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject.
2746+ * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject,
2747+ * although this condition is verified by this function on DEBUG builds.
27352748 */
27362749static inline PyObject *
27372750unicode_error_get_object_impl (PyObject * self , int as_bytes )
@@ -2757,7 +2770,8 @@ unicode_error_get_reason_impl(PyObject *self)
27572770/*
27582771 * Set the underlying (str) 'reason' attribute of a Unicode Error object.
27592772 *
2760- * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject.
2773+ * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject,
2774+ * although this condition is verified by this function on DEBUG builds.
27612775 *
27622776 * Return 0 on success and -1 on failure.
27632777 */
@@ -2777,7 +2791,8 @@ unicode_error_set_reason_impl(PyObject *self, const char *reason)
27772791/*
27782792 * Set the 'start' attribute of a Unicode Error object.
27792793 *
2780- * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject.
2794+ * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject,
2795+ * although this condition is verified by this function on DEBUG builds.
27812796 *
27822797 * Return 0 on success and -1 on failure.
27832798 */
@@ -2793,7 +2808,8 @@ unicode_error_set_start_impl(PyObject *self, Py_ssize_t start)
27932808/*
27942809 * Set the 'end' attribute of a Unicode Error object.
27952810 *
2796- * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject.
2811+ * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject,
2812+ * although this condition is verified by this function on DEBUG builds.
27972813 *
27982814 * Return 0 on success and -1 on failure.
27992815 */
@@ -2852,7 +2868,8 @@ unicode_error_adjust_end(Py_ssize_t end, Py_ssize_t objlen)
28522868/*
28532869 * Get various common parameters of a Unicode Error object.
28542870 *
2855- * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject.
2871+ * The caller is responsible to ensure that 'self' is a PyUnicodeErrorObject,
2872+ * although this condition is verified by this function on DEBUG builds.
28562873 *
28572874 * Return 0 on success and -1 on failure.
28582875 *
@@ -2904,6 +2921,7 @@ _PyUnicodeError_GetParams(PyObject *self,
29042921}
29052922
29062923// --- PyUnicodeEncodeObject: 'encoding' getters ------------------------------
2924+ // Note: PyUnicodeTranslateError does not have an 'encoding' attribute.
29072925
29082926PyObject *
29092927PyUnicodeEncodeError_GetEncoding (PyObject * self )
0 commit comments