Commit graph

15 commits

Author SHA1 Message Date
yuneng-jiang
6a0d03914c
test: drop the cwd-relative sys.path.insert calls from the test suite (#37802)
* test: drop the cwd-relative sys.path.insert calls from the test suite

TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.

Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.

Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.

* test: drop the duplicate imports the sys.path sweep exposed to F811

* test(pre-call-utils): restore the os import the new bedrock tests need
2026-08-22 09:25:58 -07:00
Ishaan Jaffer
e8461b5b97
style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
Sameer Kankute
0a9861c3ec Fix: test_token_counter_lazy_imports 2026-01-08 16:44:35 +05:30
Alexsander Hamir
3b847e0d9d
refactor: migrate utils.py lazy imports to registry pattern (#18657)
* refactor: migrate utils.py lazy imports to registry pattern

- Refactored utils.py __getattr__ to use cached registry pattern (similar to __init__.py)
- Added UTILS_MODULE_NAMES tuple and _UTILS_MODULE_IMPORT_MAP to _lazy_imports_registry.py
- Added _get_utils_globals() helper function to _lazy_imports.py
- Added _lazy_import_utils_module() handler function for utils module lazy imports
- Updated _get_lazy_import_registry() to include utils module lazy imports
- Removed redundant _get_utils_globals() from utils.py (now in _lazy_imports.py)
- Added comprehensive tests for utils module lazy imports in test_lazy_imports.py

This refactoring:
- Reduces code duplication (from 670+ lines to ~10 lines in __getattr__)
- Improves maintainability (new lazy imports just need registry entry)
- Maintains consistency with __init__.py lazy import pattern
- All existing functionality preserved and tested

* Fix NameError: get_coroutine_checker not defined in check_coroutine function

* Fix lazy loading for get_coroutine_checker in function_setup and check_coroutine

- Add lazy loading for get_coroutine_checker at start of function_setup to ensure all calls use lazy-loaded version
- Fix check_coroutine function to use lazy loading pattern via getattr
- All direct calls to get_coroutine_checker() now properly use lazy import mechanism
2026-01-05 09:55:48 -08:00
Alexsander Hamir
44d309f270
refactor: Add lazy loading for get_llm_provider (#18591) 2026-01-02 13:18:57 -08:00
Alexsander Hamir
80d445a96f
feat: lazy load GuardrailItem following existing patterns (#18072)
- Add TYPES_NAMES tuple and _lazy_import_types function in _lazy_imports.py
- Remove direct import of GuardrailItem from __init__.py
- Add lazy loading handler in __getattr__ to dispatch type imports
- Add type stub for GuardrailItem in TYPE_CHECKING block
- Add test_types_lazy_imports test to verify lazy loading works
- Use from __future__ import annotations for forward reference support
- Follows same pattern as DOTPROMPT_NAMES and LLM_CONFIG_NAMES for consistency
2025-12-16 11:48:36 -08:00
Alexsander Hamir
014c74fd06
[Refactor] litellm/init.py: lazy-load AmazonConverseConfig (#18069)
- Add LLM_CONFIG_NAMES tuple and _lazy_import_llm_configs function in _lazy_imports.py
- Remove direct import of AmazonConverseConfig from __init__.py
- Add lazy loading handler in __getattr__ to dispatch LLM config imports
- Add type stub for AmazonConverseConfig in TYPE_CHECKING block
- Add test_llm_config_lazy_imports test to verify lazy loading works
- Follows same pattern as DOTPROMPT_NAMES for consistency
2025-12-16 10:48:11 -08:00
Alexsander Hamir
f8168f5063
[Refactor] litellm/init.py: lazy load dotprompt integration (#18056) 2025-12-16 07:18:11 -08:00
Alexsander Hamir
feb6924efe
[Refactor] litellm/init.py: lazy load .types.utils (#18054) 2025-12-16 06:42:17 -08:00
Alexsander Hamir
ea06fb70fb
refactor: lazy load bedrock types (#18053) 2025-12-16 06:05:01 -08:00
Alexsander Hamir
6ca812130b
[Refactor] litellm/init.py: lazy load LLMClientCache (#18008) 2025-12-16 05:44:06 -08:00
Alexsander Hamir
764a31f624
refactor: lazy load get_modified_max_tokens (#18002) 2025-12-15 12:33:01 -08:00
Alexsander Hamir
8f647dd25b
[Refactor] litellm/init.py: lazy load caches (#18001) 2025-12-15 12:13:51 -08:00
Alexsander Hamir
0629dcfdd5
[Refactor] litellm/init.py: lazy load http handlers (#17997) 2025-12-15 11:50:22 -08:00
Alexsander Hamir
93b1da7911
[Refactor] lazy imports: Use per-attribute lazy imports and extract shared constants (#17994) 2025-12-15 10:38:54 -08:00