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

Function convert_class

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

Source from the content-addressed store, hash-verified

1738 <enum 'Color'>
1739 """
1740 def convert_class(cls):
1741 nonlocal use_args
1742 cls_name = cls.__name__
1743 if use_args is None:
1744 use_args = etype._use_args_
1745 __new__ = cls.__dict__.get('__new__')
1746 if __new__ is not None:
1747 new_member = __new__.__func__
1748 else:
1749 new_member = etype._member_type_.__new__
1750 attrs = {}
1751 body = {}
1752 if __new__ is not None:
1753 body['__new_member__'] = new_member
1754 body['_new_member_'] = new_member
1755 body['_use_args_'] = use_args
1756 body['_generate_next_value_'] = gnv = etype._generate_next_value_
1757 body['_member_names_'] = member_names = []
1758 body['_member_map_'] = member_map = {}
1759 body['_value2member_map_'] = value2member_map = {}
1760 body['_hashable_values_'] = hashable_values = []
1761 body['_unhashable_values_'] = unhashable_values = []
1762 body['_unhashable_values_map_'] = {}
1763 body['_member_type_'] = member_type = etype._member_type_
1764 body['_value_repr_'] = etype._value_repr_
1765 if issubclass(etype, Flag):
1766 body['_boundary_'] = boundary or etype._boundary_
1767 body['_flag_mask_'] = None
1768 body['_all_bits_'] = None
1769 body['_singles_mask_'] = None
1770 body['_inverted_'] = None
1771 body['__or__'] = Flag.__or__
1772 body['__xor__'] = Flag.__xor__
1773 body['__and__'] = Flag.__and__
1774 body['__ror__'] = Flag.__ror__
1775 body['__rxor__'] = Flag.__rxor__
1776 body['__rand__'] = Flag.__rand__
1777 body['__invert__'] = Flag.__invert__
1778 for name, obj in cls.__dict__.items():
1779 if name in ('__dict__', '__weakref__'):
1780 continue
1781 if _is_dunder(name) or _is_private(cls_name, name) or _is_sunder(name) or _is_descriptor(obj):
1782 body[name] = obj
1783 else:
1784 attrs[name] = obj
1785 if cls.__dict__.get('__doc__') is None:
1786 body['__doc__'] = 'An enumeration.'
1787 #
1788 # double check that repr and friends are not the mixin's or various
1789 # things break (such as pickle)
1790 # however, if the method is defined in the Enum itself, don't replace
1791 # it
1792 enum_class = type(cls_name, (etype, ), body, boundary=boundary, _simple=True)
1793 for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
1794 if name not in body:
1795 # check for mixin overrides before replacing
1796 enum_method = getattr(etype, name)
1797 found_method = getattr(enum_class, name)

Callers

nothing calls this directly

Calls 15

issubclassFunction · 0.85
_is_privateFunction · 0.85
_is_sunderFunction · 0.85
_is_descriptorFunction · 0.85
getattrFunction · 0.85
setattrFunction · 0.85
isinstanceFunction · 0.85
lenFunction · 0.85
_is_single_bitFunction · 0.85
sortedFunction · 0.85
_add_alias_Method · 0.80
_add_member_Method · 0.80

Tested by

no test coverage detected