During the LaunchContext constructor or _push_environment(), we take a copy of the environment via os.environ.copy(). That function returns a dict, but it turns out that os.environ itself is an os._Environ object, not a dict. Thus, when restoring the environment in either _pop_environment() or _reset_environment(), we cannot just set os.environ to that value. Instead, we clear out the environment and then set the key/value pairs one-by-one into the environment. That maintains os.environ as a os._Environ object while also performing the desired pop or reset of the environment variables.
* [#660 Fix the restoring of os.environ to maintain type. (backport #656)](https://github.com/ros2/launch/pull/660) has been created for branch `humble`
* [#661 Fix the restoring of os.environ to maintain type. (backport #656)](https://github.com/ros2/launch/pull/661) has been created for branch `galactic`
* [#662 Fix the restoring of os.environ to maintain type. (backport #656)](https://github.com/ros2/launch/pull/662) has been created for branch `foxy`
During the LaunchContext constructor or _push_environment(), we take a copy of the environment via os.environ.copy(). That function returns a dict, but it turns out that os.environ itself is an os._Environ object, not a dict. Thus, when restoring the environment in either _pop_environment() or _reset_environment(), we cannot just set os.environ to that value. Instead, we clear out the environment and then set the key/value pairs one-by-one into the environment. That maintains os.environ as a os._Environ object while also performing the desired pop or reset of the environment variables.
Signed-off-by: Chris Lalancette clalancette@openrobotics.org