diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8e8f565..274707f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Changelog ========= +1.0.2 (2013-11-05) +------------------ + - Suppress warnings from mismatched type comparisons when generated + in RichEnum.lookup. + 1.0.1 (2013-09-20) ------------------ - Raise warnings when comparing enum values to other types, but not diff --git a/setup.py b/setup.py index f13e581..2c129a2 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='richenum', - version='1.0.1', + version='1.0.2', description='Enum library for python.', long_description=( open('README.rst').read() + '\n\n' + diff --git a/src/richenum/enums.py b/src/richenum/enums.py index a01373e..57ccd43 100644 --- a/src/richenum/enums.py +++ b/src/richenum/enums.py @@ -242,8 +242,18 @@ def members(cls): def lookup(cls, field, value): for member in cls: member_value = getattr(member, field) - if member_value == value: - return member + + # We filter warnings below; in the case where the field is a list + # of RichEnumValues and the value we're looking for is a RichEnum, + # this generates a warning due to mismatched type comparison even + # though the calling pattern is acceptable. + # n.b. There's likely a cleaner way to fix this but I was unsure if + # doing so would break the semantics of this method. + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + if member_value == value: + return member + if ( not isinstance(member_value, str) and not isinstance(member_value, unicode) and