8000 gh-100357: Convert several functions in `bltinsmodule` to AC by sobolevn · Pull Request #100358 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-100357: Convert several functions in bltinsmodule to AC #100358

New issue

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

Merged
merged 3 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Address review and change argument names
  • Loading branch information
sobolevn committed Dec 21, 2022
commit 6001c90b5d5ff037b381323856dd9687c910c6bb
55 changes: 28 additions & 27 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,9 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
/*[clinic input]
getattr as builtin_getattr

v: object
object: object
name: object
dflt: object = NULL
default: object = NULL
/

Get a named attribute from an object.
Expand All @@ -1127,19 +1127,19 @@ exist; without it, an exception is raised in that case.
[clinic start generated code]*/

static PyObject *
builtin_getattr_impl(PyObject *module, PyObject *v, PyObject *name,
PyObject *dflt)
/*[clinic end generated code: output=dd719f3bee023bc8 input=c89dfe401b53e36c]*/
builtin_getattr_impl(PyObject *module, PyObject *object, PyObject *name,
PyObject *default_value)
/*[clinic end generated code: output=74ad0e225e3f701c input=d7562cd4c3556171]*/
{
PyObject *result;

if (dflt != NULL) {
if (_PyObject_LookupAttr(v, name, &result) == 0) {
return Py_NewRef(dflt);
if (default_value != NULL) {
if (_PyObject_LookupAttr(object, name, &result) == 0) {
return Py_NewRef(default_value);
}
}
else {
result = PyObject_GetAttr(v, name);
result = PyObject_GetAttr(object, name);
}
return result;
}
Expand Down Expand Up @@ -1458,7 +1458,7 @@ PyTypeObject PyMap_Type = {
/*[clinic input]
next as builtin_next

it: object
iterator: object
default: object = NULL
/

Expand All @@ -1469,19 +1469,20 @@ it is returned instead of raising StopIteration.
[clinic start generated code]*/

static PyObject *
builtin_next_impl(PyObject *module, PyObject *it, PyObject *default_value)
/*[clinic end generated code: output=46a69959fd15f36c input=812f1b6154c81014]*/
builtin_next_impl(PyObject *module, PyObject *iterator,
PyObject *default_value)
/*[clinic end generated code: output=a38a94eeb447fef9 input=180f9984f182020f]*/
{
PyObject *res;

if (!PyIter_Check(it)) {
if (!PyIter_Check(iterator)) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object is not an iterator",
Py_TYPE(it)->tp_name);
Py_TYPE(iterator)->tp_name);
return NULL;
}

res = (*Py_TYPE(it)->tp_iternext)(it);
res = (*Py_TYPE(iterator)->tp_iternext)(iterator);
if (res != NULL) {
return res;
} else if (default_value != NULL) {
Expand Down Expand Up @@ -1594,7 +1595,7 @@ builtin_hex(PyObject *module, PyObject *number)
/*[clinic input]
iter as builtin_iter

v: object
object: object
sentinel: object = NULL
/

Expand All @@ -1605,17 +1606,17 @@ In the second form, the callable is called until it returns the sentinel.
[clinic start generated code]*/

static PyObject *
builtin_iter_impl(PyObject *module, PyObject *v, PyObject *sentinel)
/*[clinic end generated code: output=e44e927b4b674002 input=7ae9b0166003fe37]*/
builtin_iter_impl(PyObject *module, PyObject *object, PyObject *sentinel)
/*[clinic end generated code: output=12cf64203c195a94 input=a5d64d9d81880ba6]*/
{
if (sentinel == NULL)
return PyObject_GetIter(v);
if (!PyCallable_Check(v)) {
return PyObject_GetIter(object);
if (!PyCallable_Check(object)) {
PyErr_SetString(PyExc_TypeError,
"iter(v, w): v must be callable");
"iter(object, sentinel): object must be callable");
return NULL;
}
return PyCallIter_New(v, sentinel);
return PyCallIter_New(object, sentinel);
}


Expand Down Expand Up @@ -2399,7 +2400,7 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
/*[clinic input]
vars as builtin_vars

v: object = NULL
object: object = NULL
/

Show vars.
Expand All @@ -2409,16 +2410,16 @@ With an argument, equivalent to object.__dict__.
[clinic start generated code]*/

static PyObject *
builtin_vars_impl(PyObject *module, PyObject *v)
/*[clinic end generated code: output=a64017e4a4dc53fc input=4a426fb03c9b2781]*/
builtin_vars_impl(PyObject *module, PyObject *object)
/*[clinic end generated code: output=840a7f64007a3e0a input=80cbdef9182c4ba3]*/
{
PyObject *d;

if (v == NULL) {
if (object == NULL) {
d = Py_XNewRef(PyEval_GetLocals());
}
else {
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &d) == 0) {
if (_PyObject_LookupAttr(object, &_Py_ID(__dict__), &d) == 0) {
PyErr_SetString(PyExc_TypeError,
"vars() argument must have __dict__ attribute");
}
Expand Down
49 changes: 25 additions & 24 deletions Python/clinic/bltinmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0