@@ -218,8 +218,7 @@ inline bool IsNamedTupleClassImpl(const py::handle &type) {
218218 // We can only identify namedtuples heuristically, here by the presence of a _fields attribute.
219219 if (PyType_FastSubclass (reinterpret_cast <PyTypeObject *>(type.ptr ()),
220220 Py_TPFLAGS_TUPLE_SUBCLASS)) [[unlikely]] {
221- if (PyObject * const _fields = PyObject_GetAttr (type.ptr (), Py_Get_ID (_fields)))
222- [[unlikely]] {
221+ if (PyObject * const _fields = PyObject_GetAttrString (type.ptr (), " _fields" )) [[unlikely]] {
223222 bool fields_ok = static_cast <bool >(PyTuple_CheckExact (_fields));
224223 if (fields_ok) [[likely]] {
225224 for (const auto &field : py::reinterpret_borrow<py::tuple>(_fields)) {
@@ -232,8 +231,9 @@ inline bool IsNamedTupleClassImpl(const py::handle &type) {
232231 Py_DECREF (_fields);
233232 if (fields_ok) [[likely]] {
234233 // NOLINTNEXTLINE[readability-use-anyofallof]
235- for (PyObject * const name : {Py_Get_ID (_make), Py_Get_ID (_asdict)}) {
236- if (PyObject * const attr = PyObject_GetAttr (type.ptr (), name)) [[likely]] {
234+ for (const char * const name : {" _make" , " _asdict" }) {
235+ if (PyObject * const attr = PyObject_GetAttrString (type.ptr (), name))
236+ [[likely]] {
237237 const bool result = static_cast <bool >(PyCallable_Check (attr));
238238 Py_DECREF (attr);
239239 if (!result) [[unlikely]] {
@@ -311,7 +311,7 @@ inline py::tuple NamedTupleGetFields(const py::handle &object) {
311311 PyRepr (object) + " ." );
312312 }
313313 }
314- return EVALUATE_WITH_LOCK_HELD (py::getattr (type, Py_Get_ID ( _fields) ), type);
314+ return EVALUATE_WITH_LOCK_HELD (py::getattr (type, " _fields" ), type);
315315}
316316
317317inline bool IsStructSequenceClassImpl (const py::handle &type) {
@@ -325,9 +325,8 @@ inline bool IsStructSequenceClassImpl(const py::handle &type) {
325325 PyTuple_GET_ITEM (type_object->tp_bases , 0 ) == reinterpret_cast <PyObject *>(&PyTuple_Type))
326326 [[unlikely]] {
327327 // NOLINTNEXTLINE[readability-use-anyofallof]
328- for (PyObject * const name :
329- {Py_Get_ID (n_fields), Py_Get_ID (n_sequence_fields), Py_Get_ID (n_unnamed_fields)}) {
330- if (PyObject * const attr = PyObject_GetAttr (type.ptr (), name)) [[unlikely]] {
328+ for (const char * const name : {" n_fields" , " n_sequence_fields" , " n_unnamed_fields" }) {
329+ if (PyObject * const attr = PyObject_GetAttrString (type.ptr (), name)) [[unlikely]] {
331330 const bool result = static_cast <bool >(PyLong_CheckExact (attr));
332331 Py_DECREF (attr);
333332 if (!result) [[unlikely]] {
@@ -418,7 +417,7 @@ inline py::tuple StructSequenceGetFieldsImpl(const py::handle &type) {
418417 return py::tuple{fields};
419418#else
420419 const auto n_sequence_fields = thread_safe_cast<py::ssize_t >(
421- EVALUATE_WITH_LOCK_HELD (py::getattr (type, Py_Get_ID ( n_sequence_fields) ), type));
420+ EVALUATE_WITH_LOCK_HELD (py::getattr (type, " n_sequence_fields" ), type));
422421 const auto * const members = reinterpret_cast <PyTypeObject *>(type.ptr ())->tp_members ;
423422 py::tuple fields{n_sequence_fields};
424423 for (py::ssize_t i = 0 ; i < n_sequence_fields; ++i) {
@@ -489,15 +488,15 @@ inline void TotalOrderSort(py::list &list) { // NOLINT[runtime/references]
489488 // Sort with `(f'{obj.__class__.__module__}.{obj.__class__.__qualname__}', obj)`
490489 const auto sort_key_fn = py::cpp_function ([](const py::object &obj) -> py::tuple {
491490 const py::handle cls = py::type::handle_of (obj);
492- const py::str qualname{EVALUATE_WITH_LOCK_HELD (
493- PyStr (py::getattr (cls, Py_Get_ID ( __module__) )) + " ." +
494- PyStr (py::getattr (cls, Py_Get_ID ( __qualname__) )),
495- cls)};
491+ const py::str qualname{
492+ EVALUATE_WITH_LOCK_HELD ( PyStr (py::getattr (cls, " __module__" )) + " ." +
493+ PyStr (py::getattr (cls, " __qualname__" )),
494+ cls)};
496495 return py::make_tuple (qualname, obj);
497496 });
498497 {
499498 const scoped_critical_section cs{list};
500- py::getattr (list, Py_Get_ID ( sort) )(py::arg (" key" ) = sort_key_fn);
499+ py::getattr (list, " sort" )(py::arg (" key" ) = sort_key_fn);
501500 }
502501 } catch (py::error_already_set &ex2) {
503502 if (ex2.matches (PyExc_TypeError)) [[likely]] {
0 commit comments