Incomplete documentation of zero preceding width in format specification
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
The current description of zero preceding width in format is the following:
When no explicit alignment is given, preceding the width field by a zero ('0') character enables sign-aware zero-padding for numeric types, excluding complex. This is equivalent to a fill character of '0' with an alignment type of '='.
This is not complete. Consider the next code snippet:
formats = (
' <+#20.0f',
'<+#20.0f',
'+#20.0f',
' <+#020.0f',
'<+#020.0f',
'+#020.0f',
)
for fmt in formats:
print(f'Format {fmt!r:>12}: {format(1, fmt)!r}')
It has the following output:
Format ' <+#20.0f': '+1. '
Format '<+#20.0f': '+1. '
Format '+#20.0f': ' +1.'
Format ' <+#020.0f': '+1. '
Format '<+#020.0f': '+1.00000000000000000'
Format '+#020.0f': '+000000000000000001.'
The first three lines do not precede width of 20 with zero, remaining three do. Lines 4 and 5 show that one can precede width with zero even if alignment is specified. Specifically:
- If both fill char and alignment are present, then zero is ignored.
- If only alignment is present, then zero sets omitted fill char to
0(omitting fill char by default uses space as demonstrated by line 2).
Those two cases are not covered; line 6 shows the case covered by docs.
Present docs excludes complex numbers, but it is a bit tricky. One can precede width with zero only if both fill char and alignment are present (i.e., when it is ignored), otherwise an exception is raised. This case can be completely omitted as the same exception also happens when fill char itself is zero (f'{1+1j:0<+#20.0f}'). Instead, the fact that complex numbers cannot be zero-padded should be added to the description of fill char.
Linked PRs
- gh-132149
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.
Línea de trabajo
Comienza con la documentación de especificación de formato descrita en el issue y compara su redacción sobre el ancho cero con el ejemplo de Python proporcionado. Actualiza la explicación de las combinaciones explícitas de carácter de relleno y alineación, y aclara la limitación para los números complejos. Después, verifica que los casos documentados coincidan con la salida mostrada.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100