gh-116040: [Enum] fix by-value calls when second value is falsey; e.g. Cardinal(1, 0)#116072
Conversation
Lib/test/test_enum.py
Outdated
| Cardinal(1, 0) | ||
| Cardinal(-1, 0) |
There was a problem hiding this comment.
Could you test that the result is correct?
| return cls._create_( | ||
| class_name=value, | ||
| names=names, | ||
| names=names or None, |
There was a problem hiding this comment.
Add tests for something like:
Enum('empty_enum', '')Enum('empty_enum', [])Enum('empty_enum', {})Enum('empty_enum', '', type=int)Enum('empty_enum', [], type=int)Enum('empty_enum', {}, type=int)
| def __bool__(self): | ||
| return False |
There was a problem hiding this comment.
Yes, or the or None at line 730 will fail.
There was a problem hiding this comment.
Perhaps it should not take the boolean value there at first place, but use is not _not_given? I suspected that it can produce weird results if the second value is false and type is given.
There was a problem hiding this comment.
I'm not sure what you mean -- is "second value" the names parameter? If it's falsey and a type is given, a new empty enum is created (which is appropriate).
|
Thanks @ethanfurman for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
|
Sorry, @ethanfurman, I could not cleanly backport this to |
…y; e.g. Cardinal(1, 0) (pythonGH-116072) (cherry picked from commit 13ffd4b)
|
GH-116476 is a backport of this pull request to the 3.12 branch. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Sorry for not commenting at the time, but something looks suspicious in this change.
| def __bool__(self): | ||
| return False |
There was a problem hiding this comment.
Perhaps it should not take the boolean value there at first place, but use is not _not_given? I suspected that it can produce weird results if the second value is false and type is given.
| ): | ||
| empty_enum = Enum('empty_enum', nothing, type=e_type) | ||
| self.assertEqual(len(empty_enum), 0) | ||
| self.assertRaises(TypeError, 'has no members', empty_enum, 0) |
There was a problem hiding this comment.
It raises a TypeError because you try to call 'has no members'(empty_enum, 0).
There was a problem hiding this comment.
Gah. Changed to assertRaisesRegex.
| for nothing, e_type in ( | ||
| ('', None), | ||
| ('', int), | ||
| ([], None), | ||
| ([], int), | ||
| ({}, None), | ||
| ({}, int), | ||
| ): |
There was a problem hiding this comment.
It could perhaps be clearer with nested loops.
for nothing in '', [], {}:
for e_type in None, int:
...|
@serhiy-storchaka, fixes in #116508. |
…y; e.g. Cardinal(1, 0) (pythonGH-116072)
…y; e.g. Cardinal(1, 0) (pythonGH-116072)
Uh oh!
There was an error while loading. Please reload this page.