`pprint(..., expand=True)`'s "best effort" for adhering to `width=...` seems not very "best"
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Feature or enhancement
Proposal:
was playing around with this both for a pytest improvement and for a video -- and noticed that the width setting doesn't seem to play all that well with expand=True -- perhaps the width calculation is actually based on the old algorithm? (haven't looked closely yet)
import pprint
obj = {'a' * 12: 1, 'b' * 20: 2, 'c' * 30: {'d' * 5: 3, 'e' * 40: 3}}
pprint.pprint(obj)
print('===')
pprint.pprint(obj, expand=True)
this is the current output on an 80 character terminal (I've added newlines where natural wrapping occurs in the terminal)
$ python3.15 t.py
{'aaaaaaaaaaaa': 1,
'bbbbbbbbbbbbbbbbbbbb': 2,
'cccccccccccccccccccccccccccccc': {'ddddd': 3,
'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee':
3}}
===
{
'aaaaaaaaaaaa': 1,
'bbbbbbbbbbbbbbbbbbbb': 2,
'cccccccccccccccccccccccccccccc': {'ddddd': 3, 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeee': 3},
}
it makes sense to me that the old format doesn't line break properly (it wouldn't fit with the 36-space (!) indent -- but I believe the new format should be able to do better -- something similar to:
{
'aaaaaaaaaaaa': 1,
'bbbbbbbbbbbbbbbbbbbb': 2,
'cccccccccccccccccccccccccccccc': {
'ddddd': 3,
'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 3,
},
}
(which is well within the width=80 constraint)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
I believe this is also related to #149189 -- and perhaps would strengthen the ideas in that issue if resolved
Linked PRs
- gh-155926
- gh-157684
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez avec pprint.pprint(..., expand=True) et reproduisez l’exemple de l’issue avec width=80 afin d’examiner la disposition des mappings imbriqués. C’est terminé lorsque la sortie développée suit la disposition imbriquée proposée, sans retour à la ligne indésirable dans le terminal et en respectant la contrainte de largeur.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100