From 855a6c5b5974540696d2448b8a5938dae0e32a62 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 9 Jun 2019 08:11:23 -0400 Subject: [PATCH] Fix descriptor detection in enum code. --- discord/enums.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index 6fdd10a3c..ddabbe72b 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: