Skip to content

Commit

Permalink
pythongh-127011: Add __str__ and __repr__ to ConfigParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Agent-Hellboy committed Nov 19, 2024
1 parent 30aeb00 commit b3ce3f3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,14 @@ def __iter__(self):
# XXX does it break when underlying container state changed?
return itertools.chain((self.default_section,), self._sections.keys())

def __str__(self):
config_dict = {section: dict(self.items(section)) for section in self.sections()}
return str(config_dict)

def __repr__(self):
return f"<ConfigParser(default_section='{self.default_section}', interpolation={self._interpolation})>"


def _read(self, fp, fpname):
"""Parse a sectioned configuration file.
Expand Down

0 comments on commit b3ce3f3

Please sign in to comment.