Князев Максим Алексеевич, 319/2 AnnoDoc 17195
Игорь Качушкин, 314 группа AnnoDoc 15810
t1class AnnoDoc(type):t1class AnnoDoc(type):
22
3    def __new__(cls, name, bases, dct):3    def __new__(cls, name, bases, dct):
4        class_doc = dct.get('__doc__', '')4        class_doc = dct.get('__doc__', '')
5        annotations = dct.get('__annotations__', {})5        annotations = dct.get('__annotations__', {})
6        new_annotations = {}6        new_annotations = {}
7        doc_lines = [] if not class_doc else [class_doc.strip()]7        doc_lines = [] if not class_doc else [class_doc.strip()]
8        for attr, annotation in annotations.items():8        for attr, annotation in annotations.items():
9            if isinstance(annotation, str):9            if isinstance(annotation, str):
10                doc_lines.append(f'{attr}: {annotation}')10                doc_lines.append(f'{attr}: {annotation}')
11                if attr in dct:11                if attr in dct:
12                    new_annotations[attr] = type(dct[attr])12                    new_annotations[attr] = type(dct[attr])
13            else:13            else:
14                new_annotations[attr] = annotation14                new_annotations[attr] = annotation
15        if not doc_lines:15        if not doc_lines:
16            dct['__doc__'] = None16            dct['__doc__'] = None
17        else:17        else:
18            dct['__doc__'] = '\n'.join(doc_lines)18            dct['__doc__'] = '\n'.join(doc_lines)
19        if not new_annotations:19        if not new_annotations:
20            dct['__annotations__'] = {}20            dct['__annotations__'] = {}
21        else:21        else:
22            dct['__annotations__'] = new_annotations22            dct['__annotations__'] = new_annotations
23        return super().__new__(cls, name, bases, dct)23        return super().__new__(cls, name, bases, dct)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op