f | class AnnoDoc(type): | f | class AnnoDoc(type): |
| | | |
n | def __new__(cls, nm, b, d): | n | def __new__(cls, name, bases, dct): |
| base_doc = d.get('__doc__', '') | | orig = dct.get('__doc__', '') |
| extra_doc = [] | | new = [] |
| annotations = d.get('__annotations__', {}).copy() | | ann = dct.get('__annotations__', {}).copy() |
| keys = list(annotations.keys()) | | keys = list(ann.keys()) |
| for key in keys: | | for attr in keys: |
| annotation = annotations[key] | | a = ann[attr] |
| if isinstance(annotation, str): | | if isinstance(a, str): |
| extra_doc.append(f'{key}: {annotation}') | | new.append(f'{attr}: {a}') |
| if key in d: | | if attr in dct: |
| value = d[key] | | value = dct[attr] |
| annotations[key] = type(value) | | ann[attr] = type(value) |
| else: | | else: |
n | del annotations[key] | n | del ann[attr] |
| if base_doc: | | if orig: |
| d['__doc__'] = base_doc + '\n' + '\n'.join(extra_doc) | | dct['__doc__'] = orig + '\n' + '\n'.join(new) |
| elif extra_doc: | | elif new != []: |
| d['__doc__'] = '\n'.join(extra_doc) | | dct['__doc__'] = '\n'.join(new) |
| else: | | else: |
t | d['__doc__'] = None | t | dct['__doc__'] = None |
| d['__annotations__'] = annotations | | dct['__annotations__'] = ann |
| return super().__new__(cls, nm, b, d) | | return super().__new__(cls, name, bases, dct) |