-
Notifications
You must be signed in to change notification settings - Fork 577
fix: import errors for models with optional imports #1384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| from .writer import WriterModel | ||
|
|
||
| return WriterModel | ||
| raise AttributeError(f"module '{__name__}' has no attribute '{name}'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match convention, I would recommend instead doing:
raise ImportError(f"cannot import name '{name}' from '{__name__}' ({__file__})")
This is the same error message that would be printed without the __getattr__ override.
| ] | ||
|
|
||
|
|
||
| def __getattr__(name: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend setting the return type to -> Any.
|
|
||
| __all__ = ["bedrock", "model", "BedrockModel", "Model"] | ||
| # Type checking imports for static analysis | ||
| if TYPE_CHECKING: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, does this help with autocomplete? For example, if in my code editor I start typing from strands.modules import, will it show what is in this list as options?
Description
Implementing lazy loading in models init.py file
Related Issues
Documentation PR
Type of Change
Bug fix
New feature
Breaking change
Documentation update
Other (please describe):
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.