Header access methods in EmailMessage return strings, not header objects
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Comienza con los métodos de acceso a las cabeceras de EmailMessage y la documentación de get_param() de la clase base Message descritos en el issue. Compara el acceso basado en params documentado con los valores de retorno actuales en forma de cadenas y, después, inspecciona el comportamiento relacionado con el manejo de parámetros. El trabajo debe considerarse terminado cuando el comportamiento de API elegido sea coherente en el código, la documentación y las pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
The behavior of the EmailMessage class does not match what the documentation says it will do when code using the class tries to fetch a header parameter value.
The class has a get_param() method, but that's defined in a base class, and the documentation says that the base class (Message) should only be used when maintaining legacy code. Instead, we're told:
Note that "existing parameter values of headers may be accessed through the params attribute of the header value (for example, msg['Content-Type'].params['charset']).
The problem is that msg['Content-Type'] returns a string, not a header object, which Python correctly complains "has no attribute 'params'."
It's not obvious (to me, anyway) why set_param() (also defined in the same base class) is OK to use, but not get_param() (which, by the way, actually works, in contrast with the approach given in the documentation). The docstring for get_param() (which I used to think of as the "canonical documentation" until one of the core devs gently set me straight) gives no indication that using get_param() is frowned upon, but the really canonical documentation says
This is a legacy method. On the EmailMessage class its functionality is replaced by the params property of the individual header objects returned by the header access methods.
I suppose this ticket could go either way: a bug in the code (which should be returning objects instead of strings for the header access methods) or a bug in the documentation. I went with the first option, since if the documentation is wrong and the header access methods really are supposed to return strings, then something will still need to be done with the code to expose the needed functionality. There's a comment on _get_params_preserve() (which get_params() and get_param() both use to do their thing) asking if it should be part of the public interface, so that would be one solution (though I'd still want to know why get_param() shouldn't be used).
Environment
- Python 3.11.1 (v3.11.1:a7a450f84a, Dec 6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Context
I ended up in this module when I noticed that the cgi module has been deprecated.
Deprecated since version 3.11, will be removed in version 3.13: The cgi module is deprecated (see PEP 594 for details and alternatives).
The FieldStorage class can typically be replaced with urllib.parse.parse_qsl() for GET and HEAD requests, and the email.message module or multipart for POST and PUT. Most utility functions have replacements.
That's about it for guidance on how to make the transition. I feel a little bit like as if I'm being thrown back to my experiences as a young dad trying to assemble the toys on Christmas Eve with instructions written in a foreign language. 😅
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 558
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
docs pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
build type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
stdlib topic-email type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de python/cpython
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
PolicyEngine/policyengine-us#9559 ·
-
priority: p3
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
googleapis/librarian#7636 ·
-
from:qa priority:P2 reliability tech-debt
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
spec-kitty/spec-kitty#4874 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100