fix: Python 3.9 PEP-604 compatibility via __future__ annotations#13765
Closed
capt-marbles wants to merge 1 commit into
Closed
fix: Python 3.9 PEP-604 compatibility via __future__ annotations#13765capt-marbles wants to merge 1 commit into
capt-marbles wants to merge 1 commit into
Conversation
Collaborator
|
Related: #7611 adds the same future import to 3 remaining files — this PR is a superset. |
1 similar comment
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.
79834fa to
cba5aef
Compare
This was referenced Apr 24, 2026
Author
|
Retiring this older PR rather than dragging a stale, conflicted branch through current The active Hermes fixes are now focused on the newer, cleaner PRs. If this issue resurfaces against current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withTypeError, which cascades intoImportErrorfor dependent modules. The most visible symptom was the/modelcommand crashing with:Changes
from __future__ import annotationsto 115 Hermes source files that use PEP-604 union type syntaxX | Nonesyntax a string literal at parse time (compatible with 3.9+) rather than a runtime type union (3.10+)Testing
utils.base_url_host_matches,hermes_cli.model_switch,cli.HermesCLI— all imports succeed/modelcommand: ✅ No longer throws ImportErrorBackward compatibility
Zero breaking changes.
from __future__ import annotationsis 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