Skip to content

fix: resolve forward references in DI container and Router#47

Merged
psincraian merged 3 commits into
mainfrom
psincraian/fix-forward-ref
Jan 11, 2026
Merged

fix: resolve forward references in DI container and Router#47
psincraian merged 3 commits into
mainfrom
psincraian/fix-forward-ref

Conversation

@psincraian

Copy link
Copy Markdown
Owner

Summary

Fix NameError when DI container and Router encounter forward reference type annotations that aren't resolvable in the current namespace. This occurs when types are imported locally (inside configure() methods) or under TYPE_CHECKING blocks.

Changes

  • Container builds a namespace including all registered types before calling get_type_hints()
  • Router gracefully falls back to raw annotations when forward references can't be resolved
  • Added comprehensive tests for both components

Testing

All 484 tests pass across myfy-core, myfy-web, and myfy-user packages.

🤖 Generated with Claude Code

psincraian and others added 3 commits January 11, 2026 22:06
Fix NameError when DI container and Router encounter forward reference type
annotations that aren't resolvable in the current namespace. This occurs when
types are imported locally (inside configure() methods) or under TYPE_CHECKING
blocks with `from __future__ import annotations`.

The container now builds a namespace including all registered types before
calling get_type_hints(), and the Router gracefully falls back to raw
annotations when forward references can't be resolved.

Fixes forward reference error with PasswordHasher in myfy-user where
UserModule couldn't initialize due to forward reference resolution failures.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Remove commented-out import examples that triggered ERA001 (ruff)
- Add type: ignore[unresolved-reference] for intentionally undefined
  types in forward reference tests (ty)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@psincraian psincraian merged commit f8f5d87 into main Jan 11, 2026
4 checks passed
@psincraian psincraian deleted the psincraian/fix-forward-ref branch January 11, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant