python / python/cpython

Add __str__ and __repr__ to ConfigParser for Better Debugging and Unit Testing

Aperta
#127,011 23 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Feature or enhancement

Proposal:

The ConfigParser class supports dictionary-like operations, including the contains protocol for checking section existence using the in operator. However, it lacks str and repr methods, essential for providing human-readable and developer-friendly representations of the configuration data. Adding these methods would enhance its usability, particularly for debugging, logging, and unit testing, by offering clear insights into its internal state.

current behavior:

str_resp: <configparser.ConfigParser object at 0x7f57e7cc5160>
repr_resp: <configparser.ConfigParser object at 0x7f57e7cc5160>

suggested behavior:


str_resp: {'GERRIT': {'api_key': 'val'}}
repr_resp: <ConfigParser: {'GERRIT': {'api_key': 'val'}}>

I haven’t started a thread on Python Discourse as this is a straightforward feature request requiring a simple accept or reject decision. I'd appreciate the clarification on whether there was a specific design reason for not including str and repr. If approved, I will raise a PR.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to the previous discussion of this feature:

No response

Linked PRs
  • gh-127014
  • gh-132966

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalla classe ConfigParser e dai relativi test unitari esistenti, quindi esamina le PR collegate gh-127014 e gh-132966 e la cronologia dei commenti prima di apportare modifiche. Il lavoro è completato quando i formati proposti per string e repr sono accettati dal progetto e coperti dai test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.