-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-36144: Update os.environ and os.environb for PEP 584 #18911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your time @chaburkland, and welcome to CPython! 😉
Just a couple of minor minor comments, but otherwise this looks good:
@chaburkland It looks like the environment isn't updating properly on the Windows builds. I think this is because Windows environment variables must be uppercased! Updating all of your test data with UPPERCASED keys should fix the failing tests. |
Co-Authored-By: Brandt Bucher <[email protected]>
Co-Authored-By: Brandt Bucher <[email protected]>
Co-Authored-By: Brandt Bucher <[email protected]>
Lib/test/test_os.py
Outdated
os.environ[overridden_key] = 'original_value' | ||
|
||
new_vars_dict = {'_A_': '1', '_B_': '2', overridden_key: '3'} | ||
expected = os.environ.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe dict(os.environ)
to emphasize that we expect the actual value to be a plain dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
actual = os.environ | new_vars_dict | ||
self.assertDictEqual(expected, actual) | ||
self.assertEqual('3', actual[overridden_key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you find a way to test whether this operation has a side effect on the process environment? (It shouldn't have. But it should for __ior__
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I extended the tests to check this is behaving as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I just wonder if we can save a few subprocesses by not testing for _B_
.
Lib/test/test_os.py
Outdated
@@ -1041,18 +1051,26 @@ def test_or_operator(self): | |||
new_vars_items = new_vars_dict.items() | |||
self.assertIs(NotImplemented, os.environ.__or__(new_vars_items)) | |||
|
|||
self._test_underlying_process_env('_A_', '') | |||
self._test_underlying_process_env('_B_', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we gain anything by testing for _B_
? It seems it's handled exactly the same as _A_
. (I'm asking because this test runs a subprocess, which is pretty expensive compared to almost everything else these tests do.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option could be checking all three with one subprocess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that would uglify the code. What's gained by checking three instead of two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anything is gained other than the code "feeling" complete in what it's testing. Admittedly, it's not actually testing different behavior.
The additional subprocess calls aren't very expensive though - it's only adding between 10 & 20 milliseconds. That being said, I don't have a strong feeling about it, so I'd be willing to remove the _B_
tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still something, and not everybody's machine is as fast. Let's cut the _B_
tests -- it's too high a price for a sense of completeness or symmetry.
@gvanrossum: Please replace |
Congrats on your first CPython contribution @chaburkland! 🍾 Looking forward to seeing more from you in the future. |
@chaburkland Congrats indeed! Great job. |
@brandtbucher
When implementing
__or__
and__ror__
, I found there to be two potential candidates for a return value, either adict
, or anos._Environ
class.I decided on returning a
dict
for two reaons.copy()
methodos._Environ
objects that are not in sync with each other.https://bugs.python.org/issue36144