Skip to content

Commit 8415943

Browse files
committed
Change str response
1 parent acfa969 commit 8415943

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/configparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ def __str__(self):
10581058
section: {key: value for key, value in self.items(section, raw=True)}
10591059
for section in self.sections()
10601060
}
1061-
return str(config_dict)
1061+
return f"<ConfigParser: {config_dict}>"
10621062

10631063

10641064
def __repr__(self):

Lib/test/test_configparser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,16 +988,18 @@ def test_str_and_repr(self):
988988
cf.add_section("sect3")
989989
cf.add_section("sect4")
990990
cf.add_section("sect5")
991-
cf.add_section("sect6") # Added more than 5 sections to trigger truncation
991+
cf.add_section("sect6")
992992
cf.set("sect1", "option1", "foo")
993993
cf.set("sect2", "option2", "bar")
994994

995+
995996
expected_str = (
996-
"{'sect1': {'option1': 'foo'}, 'sect2': {'option2': 'bar'}, 'sect3': {}, "
997-
"'sect4': {}, 'sect5': {}, 'sect6': {}}"
997+
"<ConfigParser: {'sect1': {'option1': 'foo'}, 'sect2': {'option2': 'bar'}, "
998+
"'sect3': {}, 'sect4': {}, 'sect5': {}, 'sect6': {}}>"
998999
)
9991000
self.assertEqual(str(cf), expected_str)
10001001

1002+
10011003
dict_type = type(cf._dict).__name__
10021004

10031005
expected_repr = (

0 commit comments

Comments
 (0)