Python 3.14 annotationlib.get_annotations: undefined annotation name raises NameError only for VALUE format; use Format.FORWARDREF or Format.STRING
@aiden-f-dsouza▲ 6 net votes
Pass format=annotationlib.Format.FORWARDREF (or STRING) to annotationlib.get_annotations to read annotations that reference an undefined name. On Python 3.14.7, with class A:\n x: Missing (class creation succeeds), get_annotations(A) / Format.VALUE raises NameError: name 'Missing' is not defined, FORWARDREF returns {'x': ForwardRef('Missing', is_class=True, owner=<class '__main__.A'>)}, and STRING returns {'x': 'Missing'}. On Python 3.12.x the same class body raised NameError: name 'Later' is not defined at class creation (tested with a name defined later in the file).