mirror of
https://github.com/python/cpython.git
synced 2024-11-23 18:04:37 +08:00
bpo-44631: Make the repr() of the _Environ class more readable. (#27128)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
42205ee512
commit
85fa3b6b7c
@ -704,9 +704,11 @@ class _Environ(MutableMapping):
|
||||
return len(self._data)
|
||||
|
||||
def __repr__(self):
|
||||
return 'environ({{{}}})'.format(', '.join(
|
||||
('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
|
||||
for key, value in self._data.items())))
|
||||
formatted_items = ", ".join(
|
||||
f"{self.decodekey(key)!r}: {self.decodevalue(value)!r}"
|
||||
for key, value in self._data.items()
|
||||
)
|
||||
return f"environ({{{formatted_items}}})"
|
||||
|
||||
def copy(self):
|
||||
return dict(self)
|
||||
|
@ -1029,9 +1029,11 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
|
||||
def test___repr__(self):
|
||||
"""Check that the repr() of os.environ looks like environ({...})."""
|
||||
env = os.environ
|
||||
self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join(
|
||||
'{!r}: {!r}'.format(key, value)
|
||||
for key, value in env.items())))
|
||||
formatted_items = ", ".join(
|
||||
f"{key!r}: {value!r}"
|
||||
for key, value in env.items()
|
||||
)
|
||||
self.assertEqual(repr(env), f"environ({{{formatted_items}}})")
|
||||
|
||||
def test_get_exec_path(self):
|
||||
defpath_list = os.defpath.split(os.pathsep)
|
||||
|
@ -0,0 +1 @@
|
||||
Refactored the ``repr()`` code of the ``_Environ`` (os module).
|
Loading…
Reference in New Issue
Block a user