[BUG]: `tp_name` field not initialized correctly for a nested class

Abierto
#5,132 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp, python
Área
api

Línea de trabajo

Comienza en include/pybind11/detail/class.h, en make_new_python_type(), reproduce después el caso anidado Pet.Attributes descrito en el issue e inspecciona el nombre del PyTypeObject generado. El trabajo está terminado cuando los errores de Python identifican el objeto como mymodule.Pet.Attributes en lugar de mymodule.Attributes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

triage
Required prerequisites
What version (or hash if on master) of pybind11 are you using?

2.11.1

Problem description

Consider the following bindings for a class Pet and some nested class Pet.Attributes, whichs is taken from the pybind11 docs:

py::class_<Pet> pet(m, "Pet");

py::class_<Pet::Attributes>(pet, "Attributes")
    .def(py::init<>());

pybind11 seems to be computing a wrong tp_name field for the nested class' PyTypeObject in make_new_python_type(). The class ends up being named just mymodule.Attributes instead of the expected mymodule.Pet.Attributes.

This can be demonstrated: The Python interpreter uses the wrong tp_name in error messages, for example:

import mymodule
a = mymodule.Pet.Attributes()
print(a.nonexisting)

gives the following error string:

AttributeError: 'mymodule.Attributes' object has no attribute 'nonexisting'

Please let me know if you also think this needs to be fixed. If so, I would be willing to contribute a pull request.

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

Not a regression

Lenguaje dominante
C++
Estrellas
18k
Forks
2.3k
Merge medio
5 d 7 h
PR fusionados (30 d)
53

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pybind/pybind11

Todos los issues de pybind/pybind11

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.