-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
IsEnum #69
IsEnum #69
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #69 +/- ##
==========================================
- Coverage 99.75% 99.52% -0.23%
==========================================
Files 12 12
Lines 813 850 +37
Branches 146 151 +5
==========================================
+ Hits 811 846 +35
- Misses 2 3 +1
- Partials 0 1 +1
Continue to review full report in Codecov by Sentry.
|
self._enum_cls = enum_cls | ||
|
||
def equals(self, other: Any) -> bool: | ||
return isinstance(other, self._enum_cls) |
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.
One idea to account for checking if other
is a value in the _enum_cls
could be:
if isinstance(other, Enum):
return isinstance(other, self._enum_cls)
else:
return other in {i.value for i in self._enum_cls}
Leading to:
from enum import Enum, auto
class ExampleEnum(Enum):
a = auto()
b = auto()
assert 1 == IsEnum(ExampleEnum)
assert 3 != IsEnum(ExampleEnum)
Adjusted with feedbacks from #68, still think that comment for |
Hi @samuelcolvin, I completely forgot about this PR and deleted the fork. |
Hi, sorry for the slow reply, life has been fairly busy. Yes, I think it's worth adding. Feel free to create a new PR. |
Absolutely no need to be sorry, I should have been the one not deleting the PR 🙈
I can barely imagine!
✅ |
Remark: This is a replica of #69, which I accidentally deleted. # Description In a similar fashion to #68, it introduces four types to check enum's: - `IsEnumType`: checks if a class definition is subclass of `Enum`, and possibly checks exact matching of member values using `IsStrictDict`. - `IsPartialEnumType`: checks if a class definition is subclass of `Enum`, and possibly checks partial matching of member values using `IsPartialDict`. - `IsEnum`: checks if an instance is from `Enum` or subclass (arguably this is the most "WIP", since I think it should be possible to check if a value is part of an enum members)
In a similar fashion to #68, it introduces three types to check enum's:
IsEnumType
: checks if a class definition is subclass ofEnum
, and possibly checks exact matching of member values usingIsStrictDict
.IsPartialEnumType
: checks if a class definition is subclass ofEnum
, and possibly checks partial matching of member values usingIsPartialDict
.IsEnum
: checks if an instance is fromEnum
or subclass (arguably this is the most "WIP", since I think it should be possible to check if a value is part of an enum members)I am tagging this as WIP as we didn't discuss about it.
(Worked on this as it is in the list of #3 )