Skip to content

fix: Python 3.9 PEP-604 compatibility via __future__ annotations#13765

Closed
capt-marbles wants to merge 1 commit into
NousResearch:mainfrom
capt-marbles:fix-python3.9-pep604-syntax
Closed

fix: Python 3.9 PEP-604 compatibility via __future__ annotations#13765
capt-marbles wants to merge 1 commit into
NousResearch:mainfrom
capt-marbles:fix-python3.9-pep604-syntax

Conversation

@capt-marbles

@capt-marbles capt-marbles commented Apr 22, 2026

Copy link
Copy Markdown

What it does

Fixes Python 3.9 compatibility crashes caused by PEP-604 union type syntax (str | None, dict | None, etc.).

Root cause

PEP-604 syntax (X | None) was introduced in Python 3.10. On Python 3.9, any module using this syntax fails at import time with TypeError, which cascades into ImportError for dependent modules. The most visible symptom was the /model command crashing with:

cannot import name 'base_url_host_matches' from 'utils'

Changes

  • Added from __future__ import annotations to 115 Hermes source files that use PEP-604 union type syntax
  • This import defers annotation evaluation, making the X | None syntax a string literal at parse time (compatible with 3.9+) rather than a runtime type union (3.10+)
  • No functional changes — only import additions, no logic modified

Testing

  • Python 3.9: ✅ utils.base_url_host_matches, hermes_cli.model_switch, cli.HermesCLI — all imports succeed
  • Python 3.11: ✅ Full venv reinstall, import chain works correctly
  • /model command: ✅ No longer throws ImportError

Backward compatibility

Zero breaking changes. from __future__ import annotations is compatible with Python 3.7+ and only affects how type annotations are evaluated (deferred to strings instead of runtime types).

Type: bugfix
Breaking: no
Affected areas: import compatibility, CLI commands

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #7611 adds the same future import to 3 remaining files — this PR is a superset.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #7611 adds the same future import to 3 remaining files — this PR is a superset.

Add `from __future__ import annotations` to all Hermes source files that
use PEP-604 union type syntax (`str | None`, `dict | None`, etc.).
This enables Python 3.9 compatibility while preserving modern type hints.

Root cause: PEP-604 syntax (`X | None`) was introduced in Python 3.10
but Hermes needs to run on Python 3.9 systems. Without this import,
any module using the syntax fails at import time with TypeError,
cascading into ImportError for dependent modules like utils.py.

Specifically fixes the /model command ImportError:
  cannot import name 'base_url_host_matches' from 'utils'

No functional changes — `from __future__ import annotations` only
affects type annotation evaluation, deferring them to runtime strings.
@capt-marbles

Copy link
Copy Markdown
Author

Retiring this older PR rather than dragging a stale, conflicted branch through current main.

The active Hermes fixes are now focused on the newer, cleaner PRs. If this issue resurfaces against current main, I'll reopen it as a fresh narrow patch with current tests instead of reviving this stale branch.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants