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

Method _add_value_alias_

Lib/enum.py:1210–1233  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

1208 self.__class__._add_member_(name, self)
1209
1210 def _add_value_alias_(self, value):
1211 cls = self.__class__
1212 try:
1213 if value in cls._value2member_map_:
1214 if cls._value2member_map_[value] is not self:
1215 raise ValueError('%r is already bound: %r' % (value, cls._value2member_map_[value]))
1216 return
1217 except TypeError:
1218 # unhashable value, do long search
1219 for m in cls._member_map_.values():
1220 if m._value_ == value:
1221 if m is not self:
1222 raise ValueError('%r is already bound: %r' % (value, cls._value2member_map_[value]))
1223 return
1224 try:
1225 # This may fail if value is not hashable. We can't add the value
1226 # to the map, and by-value lookups for this value will be
1227 # linear.
1228 cls._value2member_map_.setdefault(value, self)
1229 cls._hashable_values_.append(value)
1230 except TypeError:
1231 # keep track of the value in a list so containment checks are quick
1232 cls._unhashable_values_.append(value)
1233 cls._unhashable_values_map_.setdefault(self.name, []).append(value)
1234
1235 @staticmethod
1236 def _generate_next_value_(name, start, count, last_values):

Callers 2

__new__Method · 0.80

Calls 3

valuesMethod · 0.45
setdefaultMethod · 0.45
appendMethod · 0.45

Tested by 2

__new__Method · 0.64