8000 bpo-44631: Make the repr() of the _Environ class more readable. (#27128) · python/cpython@85fa3b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85fa3b6

Browse files
Leonardofreuaambv
andauthored
bpo-44631: Make the repr() of the _Environ class more readable. (#27128)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent 42205ee commit 85fa3b6

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Lib/os.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,11 @@ def __len__(self):
704704
return len(self._data)
705705

706706
def __repr__(self):
707-
return 'environ({{{}}})'.format(', '.join(
708-
('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
709-
for key, value in self._data.items())))
707+
formatted_items = ", ".join(
708+
f"{self.decodekey(key)!r}: {self.decodevalue(value)!r}"
709+
for key, value in self._data.items()
710+
)
711+
return f"environ({{{formatted_items}}})"
710712

711713
def copy(self):
712714
return dict(self)

Lib/test/test_os.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,9 +1029,11 @@ def test_items(self):
10291029
def test___repr__(self):
10301030
"""Check that the repr() of os.environ looks like environ({...})."""
10311031
env = os.environ
1032-
self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join(
1033-
'{!r}: {!r}'.format(key, value)
1034-
for key, value in env.items())))
1032+
formatted_items = ", ".join(
1033+
f"{key!r}: {value!r}"
1034+
for key, value in env.items()
1035+
)
1036+
self.assertEqual(repr(env), f"environ({{{formatted_items}}})")
10351037

10361038
def test_get_exec_path(self):
10371039
defpath_list = os.defpath.split(os.pathsep)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactored the ``repr()`` code of the ``_Environ`` (os module).

0 commit comments

Comments
 (0)
0