Леонов Никита, 418 группа SlotGen 8335
Орлов Михаил, 418 группа SlotGen 8318
f1def slotgen(number):f1def slotgen(number):
22
3    def decorator(cls):3    def decorator(cls):
4        import string4        import string
5        import itertools5        import itertools
n6        chars = string.ascii_lowercasen6        letters = string.ascii_lowercase
7        name_length = 17        length = 1
8        while len(chars) ** name_length < number:8        while len(letters) ** length < number:
9            name_length += 19            length += 1
10        slot_list = []10        slots = []
11        for name_parts in itertools.product(chars, repeat=name_length):11        for combo in itertools.product(letters, repeat=length):
12            if len(slot_list) >= number:12            if len(slots) >= number:
13                break13                break
n14            slot_list.append(''.join(name_parts))n14            slots.append(''.join(combo))
15        base_attrs = {attr_name: attr_value for attr_name, attr_value in15        original_attrs = {name: value for name, value in cls.__dict__.it
> cls.__dict__.items() if not attr_name.startswith('__')}>ems() if not name.startswith('__')}
16        new_class_dict = {'__slots__': slot_list}16        class_namespace = {'__slots__': slots}
17        for attr_name, attr_value in base_attrs.items():17        for name, value in original_attrs.items():
18            if attr_name not in slot_list:18            if name not in slots:
19                new_class_dict[attr_name] = attr_value19                class_namespace[name] = value
2020
n21        def custom_setattr(self, name, value):n21        def __setattr__(self, name, value):
22            if name in base_attrs and name not in self.__slots__:22            if name in original_attrs and name not in self.__slots__:
23                raise AttributeError(f"Can't set attribute '{name}'")23                raise AttributeError(f"Can't set attribute '{name}'")
24            object.__setattr__(self, name, value)24            object.__setattr__(self, name, value)
t25        new_class_dict['__setattr__'] = custom_setattrt25        class_namespace['__setattr__'] = __setattr__
26        return type(cls.__name__, cls.__bases__, new_class_dict)26        return type(cls.__name__, cls.__bases__, class_namespace)
27    return decorator27    return decorator
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op