Commits

Mikhail Korobov  committed a05ef5d

faster Enum._attributes method

  • Participants
  • Parent commits 059f573

Comments (0)

Files changed (1)

File src/psd_tools/constants.py

 
 class Enum(object):
 
+    _attributes_cache = None
+
     @classmethod
     def _attributes(cls):
-        return [name for name in dir(cls)
-                if name.isupper() and not name.startswith('_')]
+        if cls._attributes_cache is None:
+            attrs = [name for name in dir(cls)
+                    if name.isupper() and not name.startswith('_')]
+            cls._attributes_cache = attrs
+        return cls._attributes_cache
 
     @classmethod
     def is_known(cls, value):