Skip to content

Commit 1764785

Browse files
sergey-miryanovvstinnereendebakpt
authored
Apply suggestions from code review
Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
1 parent f5ad4df commit 1764785

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

Include/internal/pycore_tuple.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
2626
PyAPI_FUNC(PyObject *)_PyTuple_FromStackRefStealOnSuccess(const union _PyStackRef *, Py_ssize_t);
2727
PyAPI_FUNC(PyObject *)_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);
2828

29-
PyAPI_FUNC(PyObject *)_PyTuple_FromPair(PyObject *, PyObject *);
30-
PyAPI_FUNC(PyObject *)_PyTuple_FromPairSteal(PyObject *, PyObject *);
29+
PyAPI_FUNC(PyObject *) _PyTuple_FromPair(PyObject *, PyObject *);
30+
PyAPI_FUNC(PyObject *) _PyTuple_FromPairSteal(PyObject *, PyObject *);
3131

3232
typedef struct {
3333
PyObject_HEAD

Lib/test/test_capi/test_tuple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_tuple_from_pair(self):
128128
for name, ctor in ctors:
129129
with self.subTest(name):
130130
self.assertEqual(type(ctor(1, 2)), tuple)
131-
self.assertEqual(ctor(1, 2), (1, 2))
131+
self.assertEqual(ctor(1, 145325), (1, 145325))
132132
self.assertEqual(ctor(None, None), (None, None))
133133
self.assertEqual(ctor(True, False), (True, False))
134134

Modules/_testinternalcapi/tuple.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,5 @@ static PyMethodDef test_methods[] = {
3535
int
3636
_PyTestInternalCapi_Init_Tuple(PyObject *m)
3737
{
38-
if (PyModule_AddFunctions(m, test_methods) < 0) {
39-
return -1;
40-
}
41-
42-
return 0;
38+
return PyModule_AddFunctions(m, test_methods);
4339
}

Objects/tupleobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ tuple_alloc_2(void)
210210
PyTupleObject *result = _Py_FREELIST_POP(PyTupleObject, tuples[index]);
211211
if (result == NULL) {
212212
result = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
213+
if (result == NULL) {
214+
return NULL;
215+
}
213216
}
214-
if (result != NULL) {
215-
_PyTuple_RESET_HASH_CACHE(result);
216-
}
217+
_PyTuple_RESET_HASH_CACHE(result);
217218
return result;
218219
}
219220

0 commit comments

Comments
 (0)