-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-39728: enum with invalid value results in ValueError twice #18641
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1776,7 +1776,8 @@ def _missing_(cls, item): | |
# trigger not found | ||
return None | ||
self.assertIs(Color('three'), Color.blue) | ||
self.assertRaises(ValueError, Color, 7) | ||
with self.assertRaises(ValueError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This statement passes on the old code as well. Is it possible to specifically assert that a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that can (and should) be tested, with something like this: with self.assertRaises(ValueError) as cm:
Color(7)
self.assertIsNone(cm.exception.__context__) |
||
Color(7) | ||
try: | ||
Color('bad return') | ||
except TypeError as exc: | ||
|
@@ -1786,7 +1787,7 @@ def _missing_(cls, item): | |
try: | ||
Color('error out') | ||
except ZeroDivisionError as exc: | ||
self.assertTrue(isinstance(exc.__context__, ValueError)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I hadn't noticed but this test would (still) be affected by the fix. And it seems reasonable to keep : \ Instead of changing when context is added to the exception, could the default implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would break logic because from enum import Enum
class Color(Enum):
BLUE = 'blue'
RED = 'red'
UNDEFINED = None There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But in that example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you're right) I will try it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original verification here should be kept. It's checking that if using |
||
self.assertTrue(not exc.__context__) | ||
else: | ||
raise Exception('Exception not raised.') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Instantiating enum with invalid value results in ValueError twice |
Uh oh!
There was an error while loading. Please reload this page.