| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| Expand Up | @@ -27,6 +27,24 @@ Object Protocol | |||||
| instead of the :func:`repr`. | ||||||
|
|
||||||
|
|
||||||
| .. c:function:: int PyObject_HasAttrWithError(PyObject *o, const char *attr_name) | ||||||
|
|
||||||
| Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. | ||||||
| This is equivalent to the Python expression ``hasattr(o, attr_name)``. | ||||||
| On failure, return ``-1``. | ||||||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityGiven the relevance of error handling for these new functions, I think the docs should mention explicitly under which conditions users must expect exceptions.
Suggested change
Sorry, something went wrong.
encukou reacted with thumbs up emoji
All reactions
|
||||||
|
|
||||||
| .. versionadded:: 3.13 | ||||||
|
|
||||||
|
|
||||||
| .. c:function:: int PyObject_HasAttrStringWithError(PyObject *o, const char *attr_name) | ||||||
|
|
||||||
| This is the same as :c:func:`PyObject_HasAttrWithError`, but *attr_name* is | ||||||
| specified as a :c:expr:`const char*` UTF-8 encoded bytes string, | ||||||
| rather than a :c:expr:`PyObject*`. | ||||||
|
|
||||||
| .. versionadded:: 3.13 | ||||||
|
|
||||||
|
|
||||||
| .. c:function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name) | ||||||
|
|
||||||
| Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This | ||||||
| Expand All | @@ -37,8 +55,8 @@ Object Protocol | |||||
|
|
||||||
| Exceptions that occur when this calls :meth:`~object.__getattr__` and | ||||||
| :meth:`~object.__getattribute__` methods are silently ignored. | ||||||
| For proper error handling, use :c:func:`PyObject_GetOptionalAttr` or | ||||||
| :c:func:`PyObject_GetAttr` instead. | ||||||
| For proper error handling, use :c:func:`PyObject_HasAttrWithError`, | ||||||
| :c:func:`PyObject_GetOptionalAttr` or :c:func:`PyObject_GetAttr` instead. | ||||||
|
|
||||||
|
|
||||||
| .. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) | ||||||
| Expand All | @@ -52,7 +70,8 @@ Object Protocol | |||||
| Exceptions that occur when this calls :meth:`~object.__getattr__` and | ||||||
| :meth:`~object.__getattribute__` methods or while creating the temporary | ||||||
| :class:`str` object are silently ignored. | ||||||
| For proper error handling, use :c:func:`PyObject_GetOptionalAttrString` | ||||||
| For proper error handling, use :c:func:`PyObject_HasAttrStringWithError`, | ||||||
| :c:func:`PyObject_GetOptionalAttrString` | ||||||
| or :c:func:`PyObject_GetAttrString` instead. | ||||||
|
|
||||||
|
|
||||||
| Expand Down | ||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Add functions :c:func:`PyObject_HasAttrWithError`, | ||
| :c:func:`PyObject_HasAttrStringWithError`, | ||
| :c:func:`PyMapping_HasKeyWithError` and | ||
| :c:func:`PyMapping_HasKeyStringWithError`. |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityGiven the relevance of error handling for these new functions, I think the docs should mention explicitly under which conditions users must expect exceptions.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySometimes I write "On error, raise an exception and return -1." Even if in C, technically, it's more "setting" an exception, I like to use Python "raise" semantics in C, it's easy for me to map C/Python this way :-)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.