-
Notifications
You must be signed in to change notification settings - Fork 12
lazy loading of all modules in init #405
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
Conversation
| try: | ||
| module = importlib.import_module(module_path, package="eval_protocol") | ||
| return getattr(module, attr_name) | ||
| except ImportError: |
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.
Optional adapter imports raise AttributeError instead of returning None
Medium Severity
The __getattr__ handler for optional imports only catches ImportError, but when the .adapters module is importable (it always is) but an individual adapter class like WeaveAdapter isn't available (due to missing dependencies), getattr(module, attr_name) raises AttributeError. This exception is not caught, so users get an AttributeError instead of None. The old code's from .adapters import WeaveAdapter would raise ImportError: cannot import name 'WeaveAdapter', which was caught. The fix requires catching both ImportError and AttributeError.
|
@shreymodi1 how do we make sure this isn't a flaky test. I see at https://github.com/eval-protocol/python-sdk/actions/runs/20938395911/job/60298640888:
|
|
|
||
| import sys | ||
|
|
||
| __version__ = _version.get_versions()["version"] |
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.
WeaveAdapter missing from module __all__ export list
Low Severity
WeaveAdapter was accidentally omitted from __all__ during the lazy loading refactor. It's correctly added to _OPTIONAL_IMPORTS (line 115) and the TYPE_CHECKING imports (line 299), but unlike all other adapters (OpenAIResponsesAdapter, LangfuseAdapter, BraintrustAdapter, LangSmithAdapter), it's not included in the __all__ list. This breaks from eval_protocol import * for users who rely on WeaveAdapter and causes inconsistency with how other adapters are exported.
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| try: | ||
| # Lazy import to avoid ~1300ms import time at module load | ||
| from litellm.cost_calculator import cost_per_token | ||
|
|
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.
Import error silently caught by broad exception handler
Medium Severity
Moving the from litellm.cost_calculator import cost_per_token import inside the try block causes ImportError to be caught by the except Exception handler. Previously, if litellm wasn't installed, the module would fail to load with a clear error. Now, missing litellm silently sets costs to 0.0 with a misleading debug message about the model, masking a dependency issue.
Note
Improves import/startup performance via lazy loading and adds scheduled benchmarks to catch regressions.
eval_protocol/__init__.pyusing__getattr__, optional placeholders, and a lazily computed__version__; only eagerly imports conflicting symbols under pytesteval_protocol/pytest/__init__.pyto lazy-load rollout processors, adapters, and flags; adds TYPE_CHECKING hintsevaluation_test.pyandevaluation_test_utils.pyto defer imports ofSingleTurnRolloutProcessor,MCPGymRolloutProcessor, andlitellm.cost_calculatoruntil neededexception_config.pyto lazily buildDEFAULT_RETRYABLE_EXCEPTIONS(avoids importinglitellm/requests/httpxat module load) and tightens typestests/test_cli_startup_benchmark.pywith thresholds for CLI and import times; registersbenchmarkmarker inpytest.ini.github/workflows/benchmark.ymlto run daily multi-Python benchmarks, upload artifacts, and notify Slack on failureWritten by Cursor Bugbot for commit ce6742f. This will update automatically on new commits. Configure here.