Skip to content
Closed
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
Next Next commit
Test more singletons
  • Loading branch information
vstinner committed Aug 14, 2026
commit 962ef4a1db0cf81d58376ab3783d109ff494f25b
19 changes: 18 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3601,15 +3601,19 @@
assert(!PyErr_Occurred());
PyObject *obj;
long ival;
PyInterpreterState *interp = _PyInterpreterState_GET();

Check warning on line 3604 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-26.04-arm)

unused variable ‘interp’ [-Wunused-variable]

Check warning on line 3604 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-26.04)

unused variable ‘interp’ [-Wunused-variable]

Check warning on line 3604 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

unused variable ‘interp’ [-Wunused-variable]

Check warning on line 3604 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-26.04)

unused variable ‘interp’ [-Wunused-variable]

Check warning on line 3604 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-26.04-arm)

unused variable ‘interp’ [-Wunused-variable]

Check warning on line 3604 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-26.04)

unused variable ‘interp’ [-Wunused-variable]

// None
obj = Py_None;
check_singleton(obj, &_PyNone_Type);

// Ellipsis (...)
// Ellipsis (...), Py_NotImplemented
obj = Py_Ellipsis;
check_singleton(obj, &PyEllipsis_Type);

obj = Py_NotImplemented;
check_singleton(obj, &_PyNotImplemented_Type);

// False, True
check_singleton_long(Py_False, 0, 1);
check_singleton_long(Py_True, 1, 1);
Expand All @@ -3624,6 +3628,7 @@
obj = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
check_singleton_bytes(obj, 0, '\0');

// 1-character bytes strings
for (ival=0; ival <= 255; ival++) {
obj = (PyObject*)&_Py_SINGLETON(bytes_characters)[ival];
check_singleton_bytes(obj, 1, (unsigned char)ival);
Expand All @@ -3633,6 +3638,9 @@
obj = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
check_singleton_unicode(obj, 0, 0);

// Do not tests _Py_STR() strings since there is no API to list them

// 1-character Unicode strings
for (ival=0; ival <= 255; ival++) {
obj = _Py_LATIN1_CHR(ival);
check_singleton_unicode(obj, 1, ival);
Expand All @@ -3644,6 +3652,15 @@
_PyObject_ASSERT(obj, PyTuple_GET_SIZE(obj) == 0);
_PyObject_ASSERT(obj, ((PyTupleObject*)obj)->ob_hash == _PyTuple_HASH_EMPTY);

// Do not test less commoly used singletons to reduce the overhead
// of calling _Py_CheckSingletons():
//
// - PyDateTime_TimeZone_UTC
// - context_token_missing
// - hamt_bitmap_node_empty
// - interp hamt_empty
// - interp last_resort_memory_error

assert(!PyErr_Occurred());
}
#endif
Loading