Skip to content

Commit

Permalink
Fix os.environb
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jun 5, 2024
1 parent df06534 commit df97d03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,10 @@ def refresh(self):
data[encodekey(key)] = value
else:
data = environ
self._data = data

# modify in-place to keep os.environb in sync
self._data.clear()
self._data.update(data)

def _create_environ_mapping():
if name == 'nt':
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,13 @@ def test_refresh(self):
os.environ['test_env'] = 'python_value'
putenv("test_env", "new_value")
self.assertEqual(os.environ['test_env'], 'python_value')
if hasattr(os, 'environb'):
self.assertEqual(os.environb[b'test_env'], b'python_value')

os.environ.refresh()
self.assertEqual(os.environ['test_env'], 'new_value')
if hasattr(os, 'environb'):
self.assertEqual(os.environb[b'test_env'], b'new_value')


class WalkTests(unittest.TestCase):
Expand Down

0 comments on commit df97d03

Please sign in to comment.