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

Method _add_value_alias_

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

Source from the content-addressed store, hash-verified

1236 self.__class__._add_member_(name, self)
1237
1238 def _add_value_alias_(self, value):
1239 cls = self.__class__
1240 try:
1241 if value in cls._value2member_map_:
1242 if cls._value2member_map_[value] is not self:
1243 raise ValueError('%r is already bound: %r' % (value, cls._value2member_map_[value]))
1244 return
1245 except TypeError:
1246 # unhashable value, do long search
1247 for m in cls._member_map_.values():
1248 if m._value_ == value:
1249 if m is not self:
1250 raise ValueError('%r is already bound: %r' % (value, cls._value2member_map_[value]))
1251 return
1252 try:
1253 # This may fail if value is not hashable. We can't add the value
1254 # to the map, and by-value lookups for this value will be
1255 # linear.
1256 cls._value2member_map_.setdefault(value, self)
1257 cls._hashable_values_.append(value)
1258 except TypeError:
1259 # keep track of the value in a list so containment checks are quick
1260 cls._unhashable_values_.append(value)
1261 cls._unhashable_values_map_.setdefault(self.name, []).append(value)
1262
1263 @staticmethod
1264 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