| 66 | import annotationlib |
| 67 | |
| 68 | def _get_annotations(fun): |
| 69 | # In Python 3.14+, annotations are deferred by default (PEP 649). |
| 70 | # Accessing fun.__annotations__ (or inspect.get_annotations without a |
| 71 | # format) evaluates them and may raise NameError for types only |
| 72 | # available under TYPE_CHECKING. To preserve previous behavior, first |
| 73 | # try to return evaluated annotations; if that fails with NameError, |
| 74 | # fall back to returning stringified annotations instead. |
| 75 | try: |
| 76 | return inspect.get_annotations(fun) |
| 77 | except NameError: |
| 78 | return inspect.get_annotations(fun, format=annotationlib.Format.STRING) |
| 79 | else: |
| 80 | def _get_annotations(fun): |
| 81 | return fun.__annotations__ |