Skip to content
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

Add descriptive error message when environment variable not detected #23717

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

astrosticks
Copy link

@astrosticks astrosticks commented Dec 9, 2020

Using os.environ[KEY] with a non-existent environment variable key only gave a simple KeyError, so now, the error message should make more sense when encountered. Obviously, fix my style if it's not up to standard.

Linked bugtracker post: https://bugs.python.org/issue44264

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@astrosticks

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jan 10, 2021
Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create an issue on bpo to discuss this change.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@astrosticks
Copy link
Author

@iritkatriel Thank you for pointing me there- here is my post: https://bugs.python.org/issue44264

Lib/os.py Outdated Show resolved Hide resolved
Lib/os.py Outdated Show resolved Hide resolved
@@ -1133,12 +1133,12 @@ def test_key_type(self):

with self.assertRaises(KeyError) as cm:
os.environ[missing]
self.assertIs(cm.exception.args[0], missing)
self.assertIn(missing, cm.exception.args[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to make this change? If so, why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the error message has more than just the key repr in it, I use assertIn to ensure that the error message __contains__ the repr of missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see updated code, which includes repr)

@astrosticks
Copy link
Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@iritkatriel: please review the changes made to this pull request.

@astrosticks
Copy link
Author

Do I need to add the skip labels myself or does a reviewer do it?

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants