Skip to content

Commit 2333ff4

Browse files
committed
resolve comments
1 parent 076bdc0 commit 2333ff4

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

Lib/configparser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,12 @@ def read(self, filenames, encoding=None):
753753
try:
754754
with open(filename, encoding=encoding) as fp:
755755
self._read(fp, filename)
756-
self._loaded_sources.append(filename)
757756
except OSError:
758757
continue
759758
if isinstance(filename, os.PathLike):
760759
filename = os.fspath(filename)
761760
read_ok.append(filename)
761+
self._loaded_sources.extend(read_ok)
762762
return read_ok
763763

764764
def read_file(self, f, source=None):
@@ -781,7 +781,6 @@ def read_string(self, string, source='<string>'):
781781
"""Read configuration from a given string."""
782782
sfile = io.StringIO(string)
783783
self.read_file(sfile, source)
784-
self._loaded_sources.append(source)
785784

786785
def read_dict(self, dictionary, source='<dict>'):
787786
"""Read configuration from a dictionary.

Lib/test/test_configparser.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ def test_set_nonstring_types(self):
980980
self.assertRaises(TypeError, cf.set, "sect", 123, "invalid opt name!")
981981
self.assertRaises(TypeError, cf.add_section, 123)
982982

983-
def test_str_and_repr(self):
983+
def test_str(self):
984984
self.maxDiff = None
985985
cf = self.config_class(allow_no_value=True, delimiters=('=',), strict=True)
986986
cf.add_section("sect1")
@@ -998,14 +998,27 @@ def test_str_and_repr(self):
998998
)
999999
self.assertEqual(str(cf), expected_str)
10001000

1001+
def test_repr(self):
1002+
self.maxDiff = None
1003+
cf = self.config_class(allow_no_value=True, delimiters=('=',), strict=True)
1004+
cf.add_section("sect1")
1005+
cf.add_section("sect2")
1006+
cf.add_section("sect3")
1007+
cf.add_section("sect4")
1008+
cf.add_section("sect5")
1009+
cf.add_section("sect6")
1010+
cf.set("sect1", "option1", "foo")
1011+
cf.set("sect2", "option2", "bar")
1012+
cf.read_string("")
1013+
10011014
dict_type = type(cf._dict).__name__
10021015

10031016
expected_repr = (
10041017
f"<{cf.__class__.__name__}("
10051018
f"params={{'dict_type': '{dict_type}', 'allow_no_value': True, "
10061019
"'delimiters': ('=',), 'strict': True, 'default_section': 'DEFAULT', "
10071020
"'interpolation': 'BasicInterpolation'}, "
1008-
"state={'loaded_sources': [], 'sections_count': 6, "
1021+
"state={'loaded_sources': ['<string>'], 'sections_count': 6, "
10091022
"'sections': ['sect1', 'sect2', 'sect3', 'sect4', 'sect5'], "
10101023
"'sections_truncated': '...and 1 more'})>"
10111024
)

Misc/ACKS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,8 @@ Joel Rosdahl
15981598
Erik Rose
15991599
Mark Roseman
16001600
Josh Rosenberg
1601-
Jim Roskind
16021601
Prince Roshan
1602+
Jim Roskind
16031603
Brian Rosner
16041604
Ignacio Rossi
16051605
Guido van Rossum

0 commit comments

Comments
 (0)