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

Function convert_class

Lib/enum.py:1771–1947  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

1769 <enum 'Color'>
1770 """
1771 def convert_class(cls):
1772 nonlocal use_args
1773 cls_name = cls.__name__
1774 if use_args is None:
1775 use_args = etype._use_args_
1776 __new__ = cls.__dict__.get('__new__')
1777 if __new__ is not None:
1778 new_member = __new__.__func__
1779 else:
1780 new_member = etype._member_type_.__new__
1781 attrs = {}
1782 body = {}
1783 if __new__ is not None:
1784 body['__new_member__'] = new_member
1785 body['_new_member_'] = new_member
1786 body['_use_args_'] = use_args
1787 body['_generate_next_value_'] = gnv = etype._generate_next_value_
1788 body['_member_names_'] = member_names = []
1789 body['_member_map_'] = member_map = {}
1790 body['_value2member_map_'] = value2member_map = {}
1791 body['_hashable_values_'] = hashable_values = []
1792 body['_unhashable_values_'] = unhashable_values = []
1793 body['_unhashable_values_map_'] = {}
1794 body['_member_type_'] = member_type = etype._member_type_
1795 body['_value_repr_'] = etype._value_repr_
1796 if issubclass(etype, Flag):
1797 body['_boundary_'] = boundary or etype._boundary_
1798 body['_flag_mask_'] = None
1799 body['_all_bits_'] = None
1800 body['_singles_mask_'] = None
1801 body['_inverted_'] = None
1802 body['__or__'] = Flag.__or__
1803 body['__xor__'] = Flag.__xor__
1804 body['__and__'] = Flag.__and__
1805 body['__ror__'] = Flag.__ror__
1806 body['__rxor__'] = Flag.__rxor__
1807 body['__rand__'] = Flag.__rand__
1808 body['__invert__'] = Flag.__invert__
1809 for name, obj in cls.__dict__.items():
1810 if name in ('__dict__', '__weakref__'):
1811 continue
1812 if _is_dunder(name) or _is_private(cls_name, name) or _is_sunder(name) or _is_descriptor(obj):
1813 body[name] = obj
1814 else:
1815 attrs[name] = obj
1816 if cls.__dict__.get('__doc__') is None:
1817 body['__doc__'] = 'An enumeration.'
1818 #
1819 # double check that repr and friends are not the mixin's or various
1820 # things break (such as pickle)
1821 # however, if the method is defined in the Enum itself, don't replace
1822 # it
1823 enum_class = type(cls_name, (etype, ), body, boundary=boundary, _simple=True)
1824 for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
1825 if name not in body:
1826 # check for mixin overrides before replacing
1827 enum_method = getattr(etype, name)
1828 found_method = getattr(enum_class, name)

Callers

nothing calls this directly

Calls 13

_is_privateFunction · 0.85
_is_sunderFunction · 0.85
_is_descriptorFunction · 0.85
_is_single_bitFunction · 0.85
_add_alias_Method · 0.80
_add_member_Method · 0.80
bit_lengthMethod · 0.80
_is_dunderFunction · 0.70
getMethod · 0.45
itemsMethod · 0.45
__init__Method · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…