Skip to content

Conversation

@mehtarac
Copy link
Member

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

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 8.82353% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/models/__init__.py 8.82% 31 Missing ⚠️

📢 Thoughts on this report? Let us know!

from .writer import WriterModel

return WriterModel
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
Copy link
Member

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):
Copy link
Member

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:
Copy link
Member

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?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants