GH-90699: Remove remaining _Py_IDENTIFIER stdlib usage (GH-99067)

This commit is contained in:
Kumar Aditya 2022-11-08 01:36:23 +05:30 committed by GitHub
parent 1438b77997
commit be0d5008b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 53 deletions

View file

@ -10,7 +10,6 @@
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "pycore_long.h" // _PyLong_GetOne()
@ -141,10 +140,6 @@ static PyTypeObject PyDateTime_TimeZoneType;
static int check_tzinfo_subclass(PyObject *p);
_Py_IDENTIFIER(as_integer_ratio);
_Py_IDENTIFIER(fromutc);
_Py_IDENTIFIER(isoformat);
_Py_IDENTIFIER(strftime);
/* ---------------------------------------------------------------------------
* Math utilities.
@ -1323,8 +1318,6 @@ static PyObject *
call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
{
PyObject *result;
_Py_IDENTIFIER(tzname);
assert(tzinfo != NULL);
assert(check_tzinfo_subclass(tzinfo) >= 0);
assert(tzinfoarg != NULL);
@ -1332,7 +1325,7 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
if (tzinfo == Py_None)
Py_RETURN_NONE;
result = _PyObject_CallMethodIdOneArg(tzinfo, &PyId_tzname, tzinfoarg);
result = PyObject_CallMethodOneArg(tzinfo, &_Py_ID(tzname), tzinfoarg);
if (result == NULL || result == Py_None)
return result;
@ -1515,7 +1508,7 @@ make_somezreplacement(PyObject *object, char *sep, PyObject *tzinfoarg)
if (tzinfo == Py_None || tzinfo == NULL) {
return PyBytes_FromStringAndSize(NULL, 0);
}
assert(tzinfoarg != NULL);
if (format_utcoffset(buf,
sizeof(buf),
@ -1523,7 +1516,7 @@ make_somezreplacement(PyObject *object, char *sep, PyObject *tzinfoarg)
tzinfo,
tzinfoarg) < 0)
return NULL;
return PyBytes_FromStringAndSize(buf, strlen(buf));
}
@ -1533,7 +1526,6 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
PyObject *temp;
PyObject *tzinfo = get_tzinfo_member(object);
PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
_Py_IDENTIFIER(replace);
if (Zreplacement == NULL)
return NULL;
@ -1555,7 +1547,7 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
* strftime doesn't treat them as format codes.
*/
Py_DECREF(Zreplacement);
Zreplacement = _PyObject_CallMethodId(temp, &PyId_replace, "ss", "%", "%%");
Zreplacement = PyObject_CallMethod(temp, "replace", "ss", "%", "%%");
Py_DECREF(temp);
if (Zreplacement == NULL)
return NULL;
@ -2019,7 +2011,7 @@ get_float_as_integer_ratio(PyObject *floatobj)
PyObject *ratio;
assert(floatobj && PyFloat_Check(floatobj));
ratio = _PyObject_CallMethodIdNoArgs(floatobj, &PyId_as_integer_ratio);
ratio = PyObject_CallMethodNoArgs(floatobj, &_Py_ID(as_integer_ratio));
if (ratio == NULL) {
return NULL;
}
@ -2982,8 +2974,6 @@ date_today(PyObject *cls, PyObject *dummy)
{
PyObject *time;
PyObject *result;
_Py_IDENTIFIER(fromtimestamp);
time = time_time();
if (time == NULL)
return NULL;
@ -2994,7 +2984,7 @@ date_today(PyObject *cls, PyObject *dummy)
* time.time() delivers; if someone were gonzo about optimization,
* date.today() could get away with plain C time().
*/
result = _PyObject_CallMethodIdOneArg(cls, &PyId_fromtimestamp, time);
result = PyObject_CallMethodOneArg(cls, &_Py_ID(fromtimestamp), time);
Py_DECREF(time);
return result;
}
@ -3245,7 +3235,7 @@ date_isoformat(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored))
static PyObject *
date_str(PyDateTime_Date *self)
{
return _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_isoformat);
return PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(isoformat));
}
@ -3264,14 +3254,13 @@ date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
PyObject *result;
PyObject *tuple;
PyObject *format;
_Py_IDENTIFIER(timetuple);
static char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
&format))
return NULL;
tuple = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_timetuple);
tuple = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(timetuple));
if (tuple == NULL)
return NULL;
result = wrap_strftime((PyObject *)self, format, tuple,
@ -3292,7 +3281,7 @@ date_format(PyDateTime_Date *self, PyObject *args)
if (PyUnicode_GetLength(format) == 0)
return PyObject_Str((PyObject *)self);
return _PyObject_CallMethodIdOneArg((PyObject *)self, &PyId_strftime,
return PyObject_CallMethodOneArg((PyObject *)self, &_Py_ID(strftime),
format);
}
@ -3821,9 +3810,8 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *args, *state;
PyObject *getinitargs;
_Py_IDENTIFIER(__getinitargs__);
if (_PyObject_LookupAttrId(self, &PyId___getinitargs__, &getinitargs) < 0) {
if (_PyObject_LookupAttr(self, &_Py_ID(__getinitargs__), &getinitargs) < 0) {
return NULL;
}
if (getinitargs != NULL) {
@ -4368,7 +4356,7 @@ time_repr(PyDateTime_Time *self)
static PyObject *
time_str(PyDateTime_Time *self)
{
return _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_isoformat);
return PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(isoformat));
}
static PyObject *
@ -5170,7 +5158,9 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
tz);
if (self != NULL && tz != Py_None) {
/* Convert UTC to tzinfo's zone. */
self = _PyObject_CallMethodId(tz, &PyId_fromutc, "N", self);
PyObject *res = PyObject_CallMethodOneArg(tz, &_Py_ID(fromutc), self);
Py_DECREF(self);
return res;
}
return self;
}
@ -5206,7 +5196,9 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
tzinfo);
if (self != NULL && tzinfo != Py_None) {
/* Convert UTC to tzinfo's zone. */
self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "N", self);
PyObject *res = PyObject_CallMethodOneArg(tzinfo, &_Py_ID(fromutc), self);
Py_DECREF(self);
return res;
}
return self;
}
@ -5230,7 +5222,6 @@ datetime_strptime(PyObject *cls, PyObject *args)
{
static PyObject *module = NULL;
PyObject *string, *format;
_Py_IDENTIFIER(_strptime_datetime);
if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format))
return NULL;
@ -5240,7 +5231,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
if (module == NULL)
return NULL;
}
return _PyObject_CallMethodIdObjArgs(module, &PyId__strptime_datetime,
return PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
cls, string, format, NULL);
}
@ -5747,7 +5738,14 @@ datetime_repr(PyDateTime_DateTime *self)
static PyObject *
datetime_str(PyDateTime_DateTime *self)
{
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "s", " ");
PyObject *space = PyUnicode_FromString(" ");
if (space == NULL) {
return NULL;
}
PyObject *res = PyObject_CallMethodOneArg((PyObject *)self,
&_Py_ID(isoformat), space);
Py_DECREF(space);
return res;
}
static PyObject *
@ -6301,7 +6299,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
temp = (PyObject *)result;
result = (PyDateTime_DateTime *)
_PyObject_CallMethodIdOneArg(tzinfo, &PyId_fromutc, temp);
PyObject_CallMethodOneArg(tzinfo, &_Py_ID(fromutc), temp);
Py_DECREF(temp);
return result;