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