python / python/cpython

Change names of builtin types exposed in the types module

Abierto
#100,129 6 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

interpreter-core type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Merge medio
1 d 9 h
PR fusionados (30 d)
558

Descripción

Some builtin types (like int, range, map) are exposed in the builtins module under their names. int.__name__ is "int" and int.__module__ is "builtins". getattr(sys.modules[int.__module__], int.__name__) is int

Other builtin types are exposed in the types module, but their __module__ attribute is still "builtins", and their __name__ attribute is different from the name under which they are accessible in the types module. The relation between names is not obvious, when you see <class 'builtin_function_or_method'>, it is hard to defer that it is types.BuiltinFunctionType.

As result, these types cannot be pickled:

>>> pickle.dumps(types.ClassMethodDescriptorType)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <class 'classmethod_descriptor'>: attribute lookup classmethod_descriptor on builtins failed

I propose to change attributes __module__, __name__ and __qualname__ of all builtin types exposed in the types modules so that they will match names under which they are accessible.

Linked PRs
  • gh-100130
  • gh-100142
  • gh-100405
  • gh-100406

Guía de contribución

Abrir la guía de contribución

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.

Línea de trabajo

Comienza examinando los tipos integrados expuestos a través del módulo types, sus valores actuales de module, name y qualname, y los PRs vinculados gh-100130, gh-100142, gh-100405 y gh-100406. Reproduce el ejemplo de pickling de types.ClassMethodDescriptorType; se considera hecho cuando los nombres y metadatos expuestos coincidan y estos tipos se puedan serializar mediante pickling.

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

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.