Class decorator for creating a class with a metaclass.
(metaclass)
| 883 | |
| 884 | |
| 885 | def add_metaclass(metaclass): |
| 886 | """Class decorator for creating a class with a metaclass.""" |
| 887 | def wrapper(cls): |
| 888 | orig_vars = cls.__dict__.copy() |
| 889 | slots = orig_vars.get('__slots__') |
| 890 | if slots is not None: |
| 891 | if isinstance(slots, str): |
| 892 | slots = [slots] |
| 893 | for slots_var in slots: |
| 894 | orig_vars.pop(slots_var) |
| 895 | orig_vars.pop('__dict__', None) |
| 896 | orig_vars.pop('__weakref__', None) |
| 897 | if hasattr(cls, '__qualname__'): |
| 898 | orig_vars['__qualname__'] = cls.__qualname__ |
| 899 | return metaclass(cls.__name__, cls.__bases__, orig_vars) |
| 900 | return wrapper |
| 901 | |
| 902 | |
| 903 | def ensure_binary(s, encoding='utf-8', errors='strict'): |
nothing calls this directly
no outgoing calls
no test coverage detected