Undocumented handling of thousands separator for floats and differences wrt Decimal
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
Bug report
Bug description:
In docs we have:
The ',' option signals the use of a comma for a thousands separator for floating-point presentation types and for integer presentation type 'd'. For other presentation types, this option is an error. For a locale aware separator, use the 'n' integer presentation type instead.
The '_' option signals the use of an underscore for a thousands separator for floating-point presentation types and for integer presentation type 'd'. For integer presentation types 'b', 'o', 'x', and 'X', underscores will be inserted every 4 digits. For other presentation types, specifying this option is an error.
But this doesn't specify how separators are inserted for customized alignment, consider:
>>> format(0.0, '>020_f')
'0000000000000.000000'
>>> format(0.0, '<020_f')
'0.000000000000000000'
>>> format(0.0, '=020_f')
'0_000_000_000.000000'
>>> format(0.0, '^020_f')
'0000000.000000000000'
Probably it's obvious, that separators might be inserted only in case of 0-padding and = alignment, though maybe this should be mentioned explicitly.
Note also that neither from above supported by Decimal/Fraction, e.g.:
>>> format(Decimal(0.0), '=020_f')
Traceback (most recent call last):
File "<python-input-13>", line 1, in <module>
format(Decimal(0.0), '=020_f')
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid format string
>>> format(Fraction(0.0), '=020_f')
' 0.000000'
>>> format(float(Fraction(0.0)), '=020_f')
'0_000_000_000.000000'
BTW, the rationale for Fraction's behavior (see https://github.com/python/cpython/pull/100161) is "no special-casing of the particular '0=' fill-character/alignment combination", which is rather weak, IMO.
Either this should be fixed (preferred) or documented.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-131030
- gh-131067
- gh-132155
- gh-136241
- gh-136242
- gh-136649
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
Empieza leyendo la documentación del format specification mini-language y reproduce los ejemplos de float, Decimal y Fraction del issue. Revisa los PRs enlazados para entender el trabajo que ya está en curso. Se considera terminado cuando se resuelva de forma coherente el comportamiento del separador y la alineación, o se documenten las reglas observadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- documentation
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100