-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-38698: Prevent UnboundLocalError to pop up in parse_message_id #17277
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
Merged
miss-islington
merged 1 commit into
python:master
from
PCManticore:bpo-38698-unbound-local-error
Dec 5, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2638,6 +2638,12 @@ def test_get_msg_id_no_id_right_part(self): | |
) | ||
self.assertEqual(msg_id.token_type, 'msg-id') | ||
|
||
def test_get_msg_id_invalid_expected_msg_id_not_found(self): | ||
text = "Message-Id: 935-XPB-567:0:86089:180874:0:45327:9:90305:[email protected]" | ||
msg_id = parser.parse_message_id(text) | ||
self.assertDefectsEqual(msg_id.all_defects, | ||
[errors.InvalidHeaderDefect]) | ||
|
||
def test_get_msg_id_no_angle_start(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_msg_id("msgwithnoankle") | ||
|
5 changes: 5 additions & 0 deletions
5
Misc/NEWS.d/next/Library/2019-12-02-10-35-19.bpo-38698.WZnAPQ.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Prevent UnboundLocalError to pop up in parse_message_id | ||
|
||
parse_message_id() was improperly using a token defined inside an exception | ||
handler, which was raising `UnboundLocalError` on parsing an invalid value. | ||
Patch by Claudiu Popa. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'd like you to change the code like below.
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.
What is wrong with having the append call inside the
else
branch? Especially since the body of thetry
statement contains just the instruction that might fail. This seems to me like an extra nitpicky comment for a personal flavour, not necessarily an issue with the code itself.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 didn't mean your code was wrong. I apologize if you feel bad.
As I read the code again, the original author's intention seems to be the code you proposed.