Skip to content

Fix logging error message #22276

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

Closed
wants to merge 2 commits into from

Conversation

larsoner
Copy link
Contributor

Not 100% sure if this needs an issue since I considered it trivial at first -- master has this pattern:

raise ValueError("Unknown level: %r" % level)

this fails if level is a tuple. This PR switches to f-string, but an alternative to keep % would be just to do % (level,).

But when implementing a test by reusing assert_error_message I noticed that assert_error_message was not doing what I think it was intended to do -- it never really checked to make sure the emitted error message actually matched the given error message. So I refactored it to actually check that the error message matched the one passed to assert_error_message, which then required fixing a few existing tests in FormatterTest, as the messages were actually outdated.

@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).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@larsoner

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

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

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

@@ -191,10 +191,11 @@ def _checkLevel(level):
rv = level
elif str(level) == level:
if level not in _nameToLevel:
raise ValueError("Unknown level: %r" % level)
raise ValueError(f"Unknown level: {repr(level)}")
Copy link
Member

Choose a reason for hiding this comment

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

To get to this code you would need to have passed the test str(level) == level, how would a tuple do this? I wouldn't think this line needs changing.

rv = _nameToLevel[level]
else:
raise TypeError("Level not an integer or a valid string: %r" % level)
raise TypeError("Level not an integer or a valid string: "
Copy link
Member

Choose a reason for hiding this comment

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

This could just be "Level not an integer or a valid string: %s" % repr(level) which should always work. I'm not against f-strings, but there is no need to introduce them here for this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with "...: %r" % (level,)" since it's closer to the old code, but happy to push a commit to go with your variant if you want

@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.

@larsoner
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

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

@vsajip
Copy link
Member

vsajip commented Sep 18, 2020

A Travis build appears to have stalled. I'll close and re-open, then test with buildbots.

@vsajip vsajip closed this Sep 18, 2020
@vsajip vsajip reopened this Sep 18, 2020
@vsajip vsajip added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 18, 2020
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vsajip for commit c04a0a9 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 18, 2020
@vsajip
Copy link
Member

vsajip commented Sep 19, 2020

Build still stalled on Travis job. Closing and reopening to see if that unblocks it.

@vsajip vsajip closed this Sep 19, 2020
@vsajip vsajip reopened this Sep 19, 2020
@vsajip
Copy link
Member

vsajip commented Sep 25, 2020

@larsoner This PR is unfortunately blocked from merge due to a problem with either GitHub or Travis (not sure which, as it seems to be in the interface between them). If you're in a hurry to progress this, it might be an idea to create a new PR with your current changes, and seeing if that one can go through (don't close this PR, though, it might be useful for diagnosing the GH/Travis problem).

Discussion here.

@larsoner
Copy link
Contributor Author

Closing for #22276

@larsoner larsoner closed this Sep 25, 2020
miss-islington pushed a commit that referenced this pull request Sep 25, 2020
Same changes as #22276 squashed to a single commit. Just hoping to get Travis to cooperate by opening a new PR...

Automerge-Triggered-By: @vsajip
@larsoner larsoner deleted the fix-logger-level-message branch September 25, 2020 18:19
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
Same changes as python#22276 squashed to a single commit. Just hoping to get Travis to cooperate by opening a new PR...

Automerge-Triggered-By: @vsajip
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.

4 participants