Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe1b968

Browse files
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
1 parente8ab009 commitbe1b968

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+351
-352
lines changed

‎Include/cpython/object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
294294
PyAPI_FUNC(int)_PyObject_IsAbstract(PyObject*);
295295
PyAPI_FUNC(PyObject*)_PyObject_GetAttrId(PyObject*,_Py_Identifier*);
296296
PyAPI_FUNC(int)_PyObject_SetAttrId(PyObject*,_Py_Identifier*,PyObject*);
297-
#define_PyObject_LookupAttr PyObject_GetOptionalAttr
298297

299298
PyAPI_FUNC(int)_PyObject_GetMethod(PyObject*obj,PyObject*name,PyObject**method);
300299

‎Modules/_abc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ compute_abstract_methods(PyObject *self)
361361
PyObject*item=PyTuple_GET_ITEM(bases,pos);// borrowed
362362
PyObject*base_abstracts,*iter;
363363

364-
if (_PyObject_LookupAttr(item,&_Py_ID(__abstractmethods__),
364+
if (PyObject_GetOptionalAttr(item,&_Py_ID(__abstractmethods__),
365365
&base_abstracts)<0) {
366366
gotoerror;
367367
}
@@ -375,7 +375,7 @@ compute_abstract_methods(PyObject *self)
375375
Py_DECREF(base_abstracts);
376376
PyObject*key,*value;
377377
while ((key=PyIter_Next(iter))) {
378-
if (_PyObject_LookupAttr(self,key,&value)<0) {
378+
if (PyObject_GetOptionalAttr(self,key,&value)<0) {
379379
Py_DECREF(key);
380380
Py_DECREF(iter);
381381
gotoerror;

‎Modules/_asynciomodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ get_future_loop(asyncio_state *state, PyObject *fut)
248248
returnPy_NewRef(loop);
249249
}
250250

251-
if (_PyObject_LookupAttr(fut,&_Py_ID(get_loop),&getloop)<0) {
251+
if (PyObject_GetOptionalAttr(fut,&_Py_ID(get_loop),&getloop)<0) {
252252
returnNULL;
253253
}
254254
if (getloop!=NULL) {
@@ -2966,7 +2966,7 @@ task_step_handle_result_impl(asyncio_state *state, TaskObj *task, PyObject *resu
29662966
}
29672967

29682968
/* Check if `result` is a Future-compatible object */
2969-
if (_PyObject_LookupAttr(result,&_Py_ID(_asyncio_future_blocking),&o)<0) {
2969+
if (PyObject_GetOptionalAttr(result,&_Py_ID(_asyncio_future_blocking),&o)<0) {
29702970
gotofail;
29712971
}
29722972
if (o!=NULL&&o!=Py_None) {

‎Modules/_csv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
14501450
Py_DECREF(self);
14511451
returnNULL;
14521452
}
1453-
if (_PyObject_LookupAttr(output_file,
1453+
if (PyObject_GetOptionalAttr(output_file,
14541454
module_state->str_write,
14551455
&self->write)<0) {
14561456
Py_DECREF(self);

‎Modules/_ctypes/_ctypes.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
851851
returnNULL;
852852
}
853853

854-
if (_PyObject_LookupAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
854+
if (PyObject_GetOptionalAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
855855
returnNULL;
856856
}
857857
if (as_parameter) {
@@ -1495,7 +1495,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14951495
stgdict=NULL;
14961496
type_attr=NULL;
14971497

1498-
if (_PyObject_LookupAttr((PyObject*)result,&_Py_ID(_length_),&length_attr)<0) {
1498+
if (PyObject_GetOptionalAttr((PyObject*)result,&_Py_ID(_length_),&length_attr)<0) {
14991499
gotoerror;
15001500
}
15011501
if (!length_attr) {
@@ -1528,7 +1528,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
15281528
gotoerror;
15291529
}
15301530

1531-
if (_PyObject_LookupAttr((PyObject*)result,&_Py_ID(_type_),&type_attr)<0) {
1531+
if (PyObject_GetOptionalAttr((PyObject*)result,&_Py_ID(_type_),&type_attr)<0) {
15321532
gotoerror;
15331533
}
15341534
if (!type_attr) {
@@ -1720,7 +1720,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
17201720
}
17211721
}
17221722

1723-
if (_PyObject_LookupAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
1723+
if (PyObject_GetOptionalAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
17241724
returnNULL;
17251725
}
17261726
if (as_parameter) {
@@ -1784,7 +1784,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
17841784
}
17851785
}
17861786

1787-
if (_PyObject_LookupAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
1787+
if (PyObject_GetOptionalAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
17881788
returnNULL;
17891789
}
17901790
if (as_parameter) {
@@ -1919,7 +1919,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
19191919
}
19201920
}
19211921

1922-
if (_PyObject_LookupAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
1922+
if (PyObject_GetOptionalAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
19231923
returnNULL;
19241924
}
19251925
if (as_parameter) {
@@ -2054,7 +2054,7 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20542054
if (result==NULL)
20552055
returnNULL;
20562056

2057-
if (_PyObject_LookupAttr((PyObject*)result,&_Py_ID(_type_),&proto)<0) {
2057+
if (PyObject_GetOptionalAttr((PyObject*)result,&_Py_ID(_type_),&proto)<0) {
20582058
returnNULL;
20592059
}
20602060
if (!proto) {
@@ -2266,7 +2266,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
22662266
PyObject*exc=PyErr_GetRaisedException();
22672267
Py_DECREF(parg);
22682268

2269-
if (_PyObject_LookupAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
2269+
if (PyObject_GetOptionalAttr(value,&_Py_ID(_as_parameter_),&as_parameter)<0) {
22702270
Py_XDECREF(exc);
22712271
returnNULL;
22722272
}
@@ -2429,7 +2429,7 @@ converters_from_argtypes(PyObject *ob)
24292429
}
24302430
*/
24312431

2432-
if (_PyObject_LookupAttr(tp,&_Py_ID(from_param),&cnv) <=0) {
2432+
if (PyObject_GetOptionalAttr(tp,&_Py_ID(from_param),&cnv) <=0) {
24332433
Py_DECREF(converters);
24342434
Py_DECREF(ob);
24352435
if (!PyErr_Occurred()) {
@@ -2489,7 +2489,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
24892489
return-1;
24902490
}
24912491
stgdict->restype=Py_NewRef(ob);
2492-
if (_PyObject_LookupAttr(ob,&_Py_ID(_check_retval_),
2492+
if (PyObject_GetOptionalAttr(ob,&_Py_ID(_check_retval_),
24932493
&stgdict->checker)<0)
24942494
{
24952495
return-1;
@@ -3275,7 +3275,7 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ign
32753275
"restype must be a type, a callable, or None");
32763276
return-1;
32773277
}
3278-
if (_PyObject_LookupAttr(ob,&_Py_ID(_check_retval_),&checker)<0) {
3278+
if (PyObject_GetOptionalAttr(ob,&_Py_ID(_check_retval_),&checker)<0) {
32793279
return-1;
32803280
}
32813281
oldchecker=self->checker;

‎Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
727727

728728
{
729729
PyObject*arg;
730-
if (_PyObject_LookupAttr(obj,&_Py_ID(_as_parameter_),&arg)<0) {
730+
if (PyObject_GetOptionalAttr(obj,&_Py_ID(_as_parameter_),&arg)<0) {
731731
return-1;
732732
}
733733
/* Which types should we exactly allow here?

‎Modules/_ctypes/stgdict.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ MakeAnonFields(PyObject *type)
295295
PyObject*anon_names;
296296
Py_ssize_ti;
297297

298-
if (_PyObject_LookupAttr(type,&_Py_ID(_anonymous_),&anon)<0) {
298+
if (PyObject_GetOptionalAttr(type,&_Py_ID(_anonymous_),&anon)<0) {
299299
return-1;
300300
}
301301
if (anon==NULL) {
@@ -385,7 +385,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
385385
if (fields==NULL)
386386
return0;
387387

388-
if (_PyObject_LookupAttr(type,&_Py_ID(_swappedbytes_),&tmp)<0) {
388+
if (PyObject_GetOptionalAttr(type,&_Py_ID(_swappedbytes_),&tmp)<0) {
389389
return-1;
390390
}
391391
if (tmp) {
@@ -396,7 +396,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
396396
big_endian=PY_BIG_ENDIAN;
397397
}
398398

399-
if (_PyObject_LookupAttr(type,&_Py_ID(_pack_),&tmp)<0) {
399+
if (PyObject_GetOptionalAttr(type,&_Py_ID(_pack_),&tmp)<0) {
400400
return-1;
401401
}
402402
if (tmp) {

‎Modules/_datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3791,7 +3791,7 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
37913791
PyObject*args,*state;
37923792
PyObject*getinitargs;
37933793

3794-
if (_PyObject_LookupAttr(self,&_Py_ID(__getinitargs__),&getinitargs)<0) {
3794+
if (PyObject_GetOptionalAttr(self,&_Py_ID(__getinitargs__),&getinitargs)<0) {
37953795
returnNULL;
37963796
}
37973797
if (getinitargs!=NULL) {

‎Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ expat_start_doctype_handler(XMLParserObject *self,
35303530
sysid_obj,NULL);
35313531
Py_XDECREF(res);
35323532
}
3533-
elseif (_PyObject_LookupAttr((PyObject*)self,st->str_doctype,&res)>0) {
3533+
elseif (PyObject_GetOptionalAttr((PyObject*)self,st->str_doctype,&res)>0) {
35343534
(void)PyErr_WarnEx(PyExc_RuntimeWarning,
35353535
"The doctype() method of XMLParser is ignored. "
35363536
"Define doctype() method on the TreeBuilder target.",

‎Modules/_io/bufferedio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ buffered_repr(buffered *self)
14631463
{
14641464
PyObject*nameobj,*res;
14651465

1466-
if (_PyObject_LookupAttr((PyObject*)self,&_Py_ID(name),&nameobj)<0) {
1466+
if (PyObject_GetOptionalAttr((PyObject*)self,&_Py_ID(name),&nameobj)<0) {
14671467
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
14681468
returnNULL;
14691469
}
@@ -1630,7 +1630,7 @@ _bufferedreader_read_all(buffered *self)
16301630
}
16311631
_bufferedreader_reset_buf(self);
16321632

1633-
if (_PyObject_LookupAttr(self->raw,&_Py_ID(readall),&readall)<0) {
1633+
if (PyObject_GetOptionalAttr(self->raw,&_Py_ID(readall),&readall)<0) {
16341634
gotocleanup;
16351635
}
16361636
if (readall) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp