bpo-41991: Remove _PyObject_HasAttrId by serhiy-storchaka · Pull Request #22629 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Include/cpython/object.h
11 changes: 0 additions & 11 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,17 +854,6 @@ _PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
return result;
}

int
_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
{
int result;
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
if (!oname)
return -1;
result = PyObject_HasAttr(v, oname);
return result;
}

int
_PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
{
Expand Down
13 changes: 7 additions & 6 deletions Objects/unionobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,22 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
_Py_IDENTIFIER(__args__);
PyObject *qualname = NULL;
PyObject *module = NULL;
PyObject *tmp;
PyObject *r = NULL;
int err;

int has_origin = _PyObject_HasAttrId(p, &PyId___origin__);
if (has_origin < 0) {
if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
goto exit;
}

if (has_origin) {
int has_args = _PyObject_HasAttrId(p, &PyId___args__);
if (has_args < 0) {
if (tmp) {
Py_DECREF(tmp);
if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
goto exit;
}
if (has_args) {
if (tmp) {
// It looks like a GenericAlias
Py_DECREF(tmp);
goto use_repr;
}
}
Expand Down
19 changes: 17 additions & 2 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,9 +1593,18 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset)
}
Py_DECREF(tmp);
}
else {
_PyErr_Clear(tstate);
}
}
if (exc != PyExc_SyntaxError) {
if (!_PyObject_HasAttrId(v, &PyId_msg)) {
if (_PyObject_LookupAttrId(v, &PyId_msg, &tmp) < 0) {
_PyErr_Clear(tstate);
}
else if (tmp) {
Py_DECREF(tmp);
}
else {
tmp = PyObject_Str(v);
if (tmp) {
if (_PyObject_SetAttrId(v, &PyId_msg, tmp)) {
Expand All @@ -1607,7 +1616,13 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset)
_PyErr_Clear(tstate);
}
}
if (!_PyObject_HasAttrId(v, &PyId_print_file_and_line)) {
if (_PyObject_LookupAttrId(v, &PyId_print_file_and_line, &tmp) < 0) {
_PyErr_Clear(tstate);
}
else if (tmp) {
Py_DECREF(tmp);
}
else {
if (_PyObject_SetAttrId(v, &PyId_print_file_and_line,
Py_None)) {
_PyErr_Clear(tstate);
Expand Down
6 changes: 4 additions & 2 deletions Python/pythonrun.c