Skip to content

Fix NameError from TYPE_CHECKING annotations evaluated at runtime#911

Open
Mia1Gohary wants to merge 1 commit into
mainfrom
fix_typechecking_nameerror
Open

Fix NameError from TYPE_CHECKING annotations evaluated at runtime#911
Mia1Gohary wants to merge 1 commit into
mainfrom
fix_typechecking_nameerror

Conversation

@Mia1Gohary

Copy link
Copy Markdown

Several modules imported types (e.g. Molecule, Atom, ARCSpecies) only under if TYPE_CHECKING:, but referenced them unquoted in real function/class signatures. Since those names never exist at runtime, importing arc.common (and transitively the rest of the package) raised NameError. Same issue affected a few self-referencing class annotations (e.g. Level, SSHClient) and one genuinely missing import in parser.py.

Add from __future__ import annotations to defer annotation evaluation across all 53 affected files, and add the missing TYPE_CHECKING import for ARCSpecies in arc/parser/parser.py.

Several modules imported types (e.g. Molecule, Atom, ARCSpecies) only
under `if TYPE_CHECKING:`, but referenced them unquoted in real
function/class signatures. Since those names never exist at runtime,
importing arc.common (and transitively the rest of the package) raised
NameError. Same issue affected a few self-referencing class annotations
(e.g. Level, SSHClient) and one genuinely missing import in parser.py.

Add `from __future__ import annotations` to defer annotation evaluation
across all 53 affected files, and add the missing TYPE_CHECKING import
for ARCSpecies in arc/parser/parser.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@alongd

alongd commented Jul 10, 2026

Copy link
Copy Markdown
Member

@Mia1Gohary, Thanks for digging into this!
My concern: the import-time NameError this fixes shouldn't happen on our Python 3.14 version, where annotation evaluation should be deferred by default. The crash is real on Python ≤ 3.13, but ARC doesn't support that anymore.

The fix here, I think, should be in arc/parser/parser.py: parse_active_space (line 536) annotates species: ARCSpecies, but ARCSpecies is imported nowhere in the module.
That's a static-analysis error worth fixing, with just a TYPE_CHECKING import, no future-import needed:

  from typing import TYPE_CHECKING
  if TYPE_CHECKING:
      from arc.species.species import ARCSpecies

Pleas reduce this PR to that one parser.py fix and drop from __future__ import annotations from the other 52 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants