This is a descriptor, used to define attributes that act differently when accessed through an enum member and through an enum class. Instance access is the same as property(), but access to an attribute through the enum class will instead look in the class' _member_map_ for a co
| 173 | return "auto(%r)" % self.value |
| 174 | |
| 175 | class property(DynamicClassAttribute): |
| 176 | """ |
| 177 | This is a descriptor, used to define attributes that act differently |
| 178 | when accessed through an enum member and through an enum class. |
| 179 | Instance access is the same as property(), but access to an attribute |
| 180 | through the enum class will instead look in the class' _member_map_ for |
| 181 | a corresponding enum member. |
| 182 | """ |
| 183 | |
| 184 | member = None |
| 185 | _attr_type = None |
| 186 | _cls_type = None |
| 187 | |
| 188 | def __get__(self, instance, ownerclass=None): |
| 189 | if instance is None: |
| 190 | if self.member is not None: |
| 191 | return self.member |
| 192 | else: |
| 193 | raise AttributeError( |
| 194 | '%r has no attribute %r' % (ownerclass, self.name) |
| 195 | ) |
| 196 | if self.fget is not None: |
| 197 | # use previous enum.property |
| 198 | return self.fget(instance) |
| 199 | elif self._attr_type == 'attr': |
| 200 | # look up previous attribute |
| 201 | return getattr(self._cls_type, self.name) |
| 202 | elif self._attr_type == 'desc': |
| 203 | # use previous descriptor |
| 204 | return getattr(instance._value_, self.name) |
| 205 | # look for a member by this name. |
| 206 | try: |
| 207 | return ownerclass._member_map_[self.name] |
| 208 | except KeyError: |
| 209 | raise AttributeError( |
| 210 | '%r has no attribute %r' % (ownerclass, self.name) |
| 211 | ) from None |
| 212 | |
| 213 | def __set__(self, instance, value): |
| 214 | if self.fset is not None: |
| 215 | return self.fset(instance, value) |
| 216 | raise AttributeError( |
| 217 | "<enum %r> cannot set attribute %r" % (self.clsname, self.name) |
| 218 | ) |
| 219 | |
| 220 | def __delete__(self, instance): |
| 221 | if self.fdel is not None: |
| 222 | return self.fdel(instance) |
| 223 | raise AttributeError( |
| 224 | "<enum %r> cannot delete attribute %r" % (self.clsname, self.name) |
| 225 | ) |
| 226 | |
| 227 | def __set_name__(self, ownerclass, name): |
| 228 | self.name = name |
| 229 | self.clsname = ownerclass.__name__ |
| 230 | |
| 231 | |
| 232 | class _proto_member: |
no outgoing calls
searching dependent graphs…