MCPcopy Index your code
hub / github.com/RustPython/RustPython / property

Class property

Lib/enum.py:174–228  ·  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

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

test_copy_atomicMethod · 0.68
test_deepcopy_atomicMethod · 0.68
writeMethod · 0.68
__new__Method · 0.68
test_gh_115618Method · 0.68
test_property_nameMethod · 0.68
test_docstring_copy2Method · 0.68