MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / convert_class

Function convert_class

tools/python-3.11.9-amd64/Lib/enum.py:1668–1813  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

1666 <enum 'Color'>
1667 """
1668 def convert_class(cls):
1669 nonlocal use_args
1670 cls_name = cls.__name__
1671 if use_args is None:
1672 use_args = etype._use_args_
1673 __new__ = cls.__dict__.get('__new__')
1674 if __new__ is not None:
1675 new_member = __new__.__func__
1676 else:
1677 new_member = etype._member_type_.__new__
1678 attrs = {}
1679 body = {}
1680 if __new__ is not None:
1681 body['__new_member__'] = new_member
1682 body['_new_member_'] = new_member
1683 body['_use_args_'] = use_args
1684 body['_generate_next_value_'] = gnv = etype._generate_next_value_
1685 body['_member_names_'] = member_names = []
1686 body['_member_map_'] = member_map = {}
1687 body['_value2member_map_'] = value2member_map = {}
1688 body['_unhashable_values_'] = []
1689 body['_member_type_'] = member_type = etype._member_type_
1690 body['_value_repr_'] = etype._value_repr_
1691 if issubclass(etype, Flag):
1692 body['_boundary_'] = boundary or etype._boundary_
1693 body['_flag_mask_'] = None
1694 body['_all_bits_'] = None
1695 body['_singles_mask_'] = None
1696 body['_inverted_'] = None
1697 body['__or__'] = Flag.__or__
1698 body['__xor__'] = Flag.__xor__
1699 body['__and__'] = Flag.__and__
1700 body['__ror__'] = Flag.__ror__
1701 body['__rxor__'] = Flag.__rxor__
1702 body['__rand__'] = Flag.__rand__
1703 body['__invert__'] = Flag.__invert__
1704 for name, obj in cls.__dict__.items():
1705 if name in ('__dict__', '__weakref__'):
1706 continue
1707 if _is_dunder(name) or _is_private(cls_name, name) or _is_sunder(name) or _is_descriptor(obj):
1708 body[name] = obj
1709 else:
1710 attrs[name] = obj
1711 if cls.__dict__.get('__doc__') is None:
1712 body['__doc__'] = 'An enumeration.'
1713 #
1714 # double check that repr and friends are not the mixin's or various
1715 # things break (such as pickle)
1716 # however, if the method is defined in the Enum itself, don't replace
1717 # it
1718 enum_class = type(cls_name, (etype, ), body, boundary=boundary, _simple=True)
1719 for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
1720 if name not in body:
1721 # check for mixin overrides before replacing
1722 enum_method = getattr(etype, name)
1723 found_method = getattr(enum_class, name)
1724 object_method = getattr(object, name)
1725 data_type_method = getattr(member_type, name)

Callers

nothing calls this directly

Calls 13

_is_privateFunction · 0.85
_is_sunderFunction · 0.85
_is_descriptorFunction · 0.85
propertyClass · 0.85
_is_single_bitFunction · 0.85
sortedFunction · 0.85
_is_dunderFunction · 0.70
typeClass · 0.50
getMethod · 0.45
itemsMethod · 0.45
__set_name__Method · 0.45
__init__Method · 0.45

Tested by

no test coverage detected