fix: raise NameError for undefined names in state var annotations

FL
2d ago
+137-20

Closes #7488.

With from __future__ import annotations, an undefined name in a state var annotation (for example items: list[Item] = [] where Item is not defined) raised TypeError: Unsupported type ForwardRef('list[Item]') for guess_type deep inside var typing. 0.9.12 raised NameError: name 'Item' is not defined, which names the missing symbol.

This restores the NameError, including for a var declared without a default (items: list[Item]), where the annotation is widened to Optional. is_dataframe in reflex_base/utils/types.py now also tolerates an unresolved ForwardRef, which has no __name__. Added tests in tests/units/test_state.py and tests/units/utils/test_utils.py that fail without the change.

An independent review environment ran the full unit suite in chunks, not in one uninterrupted run (12,699 passed), on Python 3.11 to 3.13; I did not run it myself. I did not run lint or the full CI matrix locally; CI will.

News fragment included.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)