-
-
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
bpo-38698: Prevent UnboundLocalError to pop up in parse_message_id #17277
Conversation
I'm not sure if this is NEWS worthy and can't apply "skip news" by myself. |
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.
Since you are the core developer, I add you as the reviewer for this PR.
Please take a look at this PR, please.
This issue should be fixed and the solution is very easy to fix.
@@ -2113,7 +2113,8 @@ def parse_message_id(value): | |||
except errors.HeaderParseError: | |||
message_id.defects.append(errors.InvalidHeaderDefect( | |||
"Expected msg-id but found {!r}".format(value))) | |||
message_id.append(token) | |||
else: |
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.
message_id = MessageID()
try:
token, value = get_msg_id(value)
+ message_id.append(token)
except errors.HeaderParseError:
message_id.defects.append(errors.InvalidHeaderDefect(
"Expected msg-id but found {!r}".format(value)))
- else:
- message_id.append(token)
return message_id
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 the try
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.
@@ -2113,7 +2113,8 @@ def parse_message_id(value): | |||
except errors.HeaderParseError: | |||
message_id.defects.append(errors.InvalidHeaderDefect( | |||
"Expected msg-id but found {!r}".format(value))) | |||
message_id.append(token) | |||
else: |
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.
@corona10 We do need a NEWS item for this, it is a bugfix. Skip News label should be used only for trivial doc changes. The changes look good, thanks for your contribution @PCManticore, can you please add a NEWS entry? Devguide has explanation on using the |
parse_message_id() was improperly using a token defined inside an exception handler, which was raising `UnboundLocalError` on parsing an invalid value.
14ad49b
to
1dddda0
Compare
@maxking Makes sense, all done! |
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.
Fix LGTM!
Sorry, I can't merge this PR. Reason: |
I think this can be backported to 3.8 too which has the same issue. |
You are of course right @tirkarthi :) |
Thanks @PCManticore for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
GH-17476 is a backport of this pull request to the 3.8 branch. |
…ythonGH-17277) parse_message_id() was improperly using a token defined inside an exception handler, which was raising `UnboundLocalError` on parsing an invalid value. https://bugs.python.org/issue38698 (cherry picked from commit bb81549) Co-authored-by: Claudiu Popa <[email protected]>
…H-17277) parse_message_id() was improperly using a token defined inside an exception handler, which was raising `UnboundLocalError` on parsing an invalid value. https://bugs.python.org/issue38698 (cherry picked from commit bb81549) Co-authored-by: Claudiu Popa <[email protected]>
…ythonGH-17277) parse_message_id() was improperly using a token defined inside an exception handler, which was raising `UnboundLocalError` on parsing an invalid value. https://bugs.python.org/issue38698
parse_message_id() was improperly using a token defined inside an exception
handler, which was raising
UnboundLocalError
on parsing an invalid value.https://bugs.python.org/issue38698
Automerge-Triggered-By: @maxking