MCPcopy Index your code
hub / github.com/python/cpython / property

Class property

Lib/enum.py:175–229  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

173 return "auto(%r)" % self.value
174
175class 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
232class _proto_member:

Callers 15

ast.pyFile · 0.85
CalendarClass · 0.85
_add_member_Method · 0.85
__init__.pyFile · 0.85
HandlerClass · 0.85
_delegating_propertyFunction · 0.85
NonCallableMockClass · 0.85
test_copy_atomicMethod · 0.85
test_deepcopy_atomicMethod · 0.85
IClass · 0.85
CClass · 0.85
EClass · 0.85

Calls

no outgoing calls

Tested by 15

test_copy_atomicMethod · 0.68
test_deepcopy_atomicMethod · 0.68
writeMethod · 0.68
test_store_attr_slotMethod · 0.68
__new__Method · 0.68
test_builtin_wrapperMethod · 0.68
test_gh_115618Method · 0.68
test_property_nameMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…