Skip to content

Commit 65b7e94

Browse files
gh-114258: Use Argument Clinic for __repr__ (GH-160011)
1 parent 6fd15f0 commit 65b7e94

12 files changed

Lines changed: 129 additions & 65 deletions

File tree

‎Modules/clinic/mmapmodule.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/mmapmodule.c‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,16 @@ mmap_mmap___exit___impl(mmap_object *self, PyObject *exc_type,
12561256
return mmap_mmap_close_impl(self);
12571257
}
12581258

1259+
/*[clinic input]
1260+
@critical_section
1261+
mmap.mmap.__repr__ as mmap__repr__method
1262+
1263+
op: self(type="PyObject *")
1264+
[clinic start generated code]*/
1265+
12591266
static PyObject *
1260-
mmap__repr__method_lock_held(PyObject *op)
1267+
mmap__repr__method_impl(PyObject *op)
1268+
/*[clinic end generated code: output=c896c8c4cd07228c input=a030361fbcfe851a]*/
12611269
{
12621270
mmap_object *mobj = mmap_object_CAST(op);
12631271

@@ -1301,16 +1309,6 @@ mmap__repr__method_lock_held(PyObject *op)
13011309
}
13021310
}
13031311

1304-
static PyObject *
1305-
mmap__repr__method(PyObject *op)
1306-
{
1307-
PyObject *result;
1308-
Py_BEGIN_CRITICAL_SECTION(op);
1309-
result = mmap__repr__method_lock_held(op);
1310-
Py_END_CRITICAL_SECTION();
1311-
return result;
1312-
}
1313-
13141312
#ifdef MS_WINDOWS
13151313
/*[clinic input]
13161314
@critical_section

‎Objects/bytearrayobject.c‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,16 @@ bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
11821182
return -1;
11831183
}
11841184

1185+
/*[clinic input]
1186+
@critical_section
1187+
bytearray.__repr__
1188+
1189+
op: self(type="PyObject *")
1190+
[clinic start generated code]*/
1191+
11851192
static PyObject *
1186-
bytearray_repr_lock_held(PyObject *op)
1193+
bytearray_repr_impl(PyObject *op)
1194+
/*[clinic end generated code: output=4086ab6928ebab1d input=d46ad3c1f3071b27]*/
11871195
{
11881196
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
11891197
const char *className = _PyType_Name(Py_TYPE(op));
@@ -1198,16 +1206,6 @@ bytearray_repr_lock_held(PyObject *op)
11981206
return res;
11991207
}
12001208

1201-
static PyObject *
1202-
bytearray_repr(PyObject *op)
1203-
{
1204-
PyObject *ret;
1205-
Py_BEGIN_CRITICAL_SECTION(op);
1206-
ret = bytearray_repr_lock_held(op);
1207-
Py_END_CRITICAL_SECTION();
1208-
return ret;
1209-
}
1210-
12111209
static PyObject *
12121210
bytearray_str(PyObject *op)
12131211
{

‎Objects/clinic/bytearrayobject.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/clinic/dictobject.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/clinic/listobject.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/clinic/setobject.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/dictobject.c‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,23 +3772,21 @@ anydict_repr_impl(PyObject *self)
37723772
return NULL;
37733773
}
37743774

3775+
/*[clinic input]
3776+
@critical_section
3777+
dict.__repr__
3778+
3779+
self: self(type="PyObject *")
3780+
[clinic start generated code]*/
3781+
37753782
static PyObject *
3776-
dict_repr_lock_held(PyObject *self)
3783+
dict_repr_impl(PyObject *self)
3784+
/*[clinic end generated code: output=059263af818a321d input=f9c423cbdf534674]*/
37773785
{
37783786
ASSERT_DICT_LOCKED((PyDictObject *)self);
37793787
return anydict_repr_impl(self);
37803788
}
37813789

3782-
static PyObject *
3783-
dict_repr(PyObject *self)
3784-
{
3785-
PyObject *res;
3786-
Py_BEGIN_CRITICAL_SECTION(self);
3787-
res = dict_repr_lock_held(self);
3788-
Py_END_CRITICAL_SECTION();
3789-
return res;
3790-
}
3791-
37923790
static Py_ssize_t
37933791
dict_length(PyObject *self)
37943792
{

‎Objects/listobject.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,21 @@ list_dealloc(PyObject *self)
632632
}
633633
}
634634

635+
/*[clinic input]
636+
@critical_section
637+
list.__repr__
638+
639+
v: self(type="PyListObject *")
640+
[clinic start generated code]*/
641+
635642
static PyObject *
636643
list_repr_impl(PyListObject *v)
644+
/*[clinic end generated code: output=c5ffe3b9cfee36ce input=f4b85c550d11de32]*/
637645
{
646+
if (PyList_GET_SIZE(v) == 0) {
647+
return PyUnicode_FromString("[]");
648+
}
649+
638650
int res = Py_ReprEnter((PyObject*)v);
639651
if (res != 0) {
640652
return (res > 0 ? PyUnicode_FromString("[...]") : NULL);
@@ -687,20 +699,6 @@ list_repr_impl(PyListObject *v)
687699
return NULL;
688700
}
689701

690-
static PyObject *
691-
list_repr(PyObject *self)
692-
{
693-
if (PyList_GET_SIZE(self) == 0) {
694-
return PyUnicode_FromString("[]");
695-
}
696-
PyListObject *v = (PyListObject *)self;
697-
PyObject *ret = NULL;
698-
Py_BEGIN_CRITICAL_SECTION(v);
699-
ret = list_repr_impl(v);
700-
Py_END_CRITICAL_SECTION();
701-
return ret;
702-
}
703-
704702
static Py_ssize_t
705703
list_length(PyObject *a)
706704
{

‎Objects/setobject.c‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,16 @@ set_dealloc(PyObject *self)
753753
Py_TYPE(so)->tp_free(so);
754754
}
755755

756+
/*[clinic input]
757+
@critical_section
758+
set.__repr__
759+
760+
so: setobject
761+
[clinic start generated code]*/
762+
756763
static PyObject *
757-
set_repr_lock_held(PySetObject *so)
764+
set_repr_impl(PySetObject *so)
765+
/*[clinic end generated code: output=5dfbb5e7f7c947ad input=f6743ec76163d7b3]*/
758766
{
759767
PyObject *result=NULL, *keys, *listrepr, *tmp;
760768
int status = Py_ReprEnter((PyObject*)so);
@@ -807,17 +815,6 @@ set_repr_lock_held(PySetObject *so)
807815
return result;
808816
}
809817

810-
static PyObject *
811-
set_repr(PyObject *self)
812-
{
813-
PySetObject *so = _PySet_CAST(self);
814-
PyObject *result;
815-
Py_BEGIN_CRITICAL_SECTION(so);
816-
result = set_repr_lock_held(so);
817-
Py_END_CRITICAL_SECTION();
818-
return result;
819-
}
820-
821818
static Py_ssize_t
822819
set_len(PyObject *self)
823820
{

0 commit comments

Comments
 (0)