aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-06-09 08:11:23 -0400
committerRapptz <[email protected]>2019-06-09 08:13:29 -0400
commit855a6c5b5974540696d2448b8a5938dae0e32a62 (patch)
tree9001264c3ef3260ef56af2b200d753df0ce07a45
parentVersion bump to 1.2.1 (diff)
downloaddiscord.py-855a6c5b5974540696d2448b8a5938dae0e32a62.tar.xz
discord.py-855a6c5b5974540696d2448b8a5938dae0e32a62.zip
Fix descriptor detection in enum code.
-rw-r--r--discord/enums.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/discord/enums.py b/discord/enums.py
index 6fdd10a3..ddabbe72 100644
--- a/discord/enums.py
+++ b/discord/enums.py
@@ -25,7 +25,6 @@ DEALINGS IN THE SOFTWARE.
"""
import types
-import inspect
from collections import namedtuple
__all__ = (
@@ -57,6 +56,9 @@ def _create_value_cls(name):
cls.__str__ = lambda self: '%s.%s' % (name, self.name)
return cls
+def _is_descriptor(obj):
+ return hasattr(obj, '__get__') or hasattr(obj, '__set__') or hasattr(obj, '__delete__')
+
class EnumMeta(type):
def __new__(cls, name, bases, attrs):
value_mapping = {}
@@ -65,16 +67,17 @@ class EnumMeta(type):
value_cls = _create_value_cls(name)
for key, value in list(attrs.items()):
- is_function = isinstance(value, types.FunctionType)
- if key[0] == '_' and not is_function:
+ is_descriptor = _is_descriptor(value)
+ if key[0] == '_' and not is_descriptor:
continue
- if is_function:
- setattr(value_cls, key, value)
- del attrs[key]
+ # Special case classmethod to just pass through
+ if isinstance(value, classmethod):
continue
- if inspect.ismethoddescriptor(value):
+ if is_descriptor:
+ setattr(value_cls, key, value)
+ del attrs[key]
continue
try: