(format, /)
| 539 | # from a regular __init__ function |
| 540 | |
| 541 | def __annotate__(format, /): |
| 542 | Format = annotationlib.Format |
| 543 | match format: |
| 544 | case Format.VALUE | Format.FORWARDREF | Format.STRING: |
| 545 | cls_annotations = {} |
| 546 | for base in reversed(__class__.__mro__): |
| 547 | cls_annotations.update( |
| 548 | annotationlib.get_annotations(base, format=format) |
| 549 | ) |
| 550 | |
| 551 | new_annotations = {} |
| 552 | for k in annotation_fields: |
| 553 | # gh-142214: The annotation may be missing in unusual dynamic cases. |
| 554 | # If so, just skip it. |
| 555 | try: |
| 556 | new_annotations[k] = cls_annotations[k] |
| 557 | except KeyError: |
| 558 | pass |
| 559 | |
| 560 | if return_type is not MISSING: |
| 561 | if format == Format.STRING: |
| 562 | new_annotations["return"] = annotationlib.type_repr(return_type) |
| 563 | else: |
| 564 | new_annotations["return"] = return_type |
| 565 | |
| 566 | return new_annotations |
| 567 | |
| 568 | case _: |
| 569 | raise NotImplementedError(format) |
| 570 | |
| 571 | # This is a flag for _add_slots to know it needs to regenerate this method |
| 572 | # In order to remove references to the original class when it is replaced |
no test coverage detected