action22k SlotGen 8414
Михаил Авраменко, 441 группа SlotGen 7991
t1import itertoolst1import itertools
2import string2import string
33
4def slotgen(number):4def slotgen(number):
55
6    def decorator(cls):6    def decorator(cls):
77
8        def generate_slot_names(count):8        def generate_slot_names(count):
9            if count <= 0:9            if count <= 0:
10                return []10                return []
11            length = 111            length = 1
12            while len(string.ascii_lowercase) ** length < count:12            while len(string.ascii_lowercase) ** length < count:
13                length += 113                length += 1
14            names = []14            names = []
15            for combo in itertools.product(string.ascii_lowercase, repea15            for combo in itertools.product(string.ascii_lowercase, repea
>t=length):>t=length):
16                if len(names) >= count:16                if len(names) >= count:
17                    break17                    break
18                names.append(''.join(combo))18                names.append(''.join(combo))
19            return names19            return names
20        slot_names = generate_slot_names(number)20        slot_names = generate_slot_names(number)
21        class_attrs = {}21        class_attrs = {}
22        for name, value in cls.__dict__.items():22        for name, value in cls.__dict__.items():
23            if not name.startswith('__') and name not in slot_names:23            if not name.startswith('__') and name not in slot_names:
24                class_attrs[name] = value24                class_attrs[name] = value
25        class_attrs['__slots__'] = tuple(slot_names)25        class_attrs['__slots__'] = tuple(slot_names)
26        new_class = type(f'Slotted{cls.__name__}', (object,), class_attr26        new_class = type(f'Slotted{cls.__name__}', (object,), class_attr
>s)>s)
27        return new_class27        return new_class
28    return decorator28    return decorator
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op