Commits
Click on a commit to change the comparison rangefix: use ContextVar cache to prevent memory leak
Use a simple module-level cache (_registered_context_vars) to store
and reuse ContextVar instances by name. This prevents the memory leak
in _configure_hooks while maintaining the original API.
Changes:
- Add _registered_context_vars cache dict at module level
- Reuse existing ContextVar instances instead of creating new ones
- Only register hooks once per unique name
- Update test to verify cache behavior instead of internal hooks
- Maintain full backward compatibility fix: improve memory leak test to avoid conflicts
Make test more robust by:
- Using unique test name to avoid conflicts with other tests
- Cleaning up test data before and after
- More focused assertions
- Proper test isolation fix: simplify type annotations for linting
Remove complex type annotations that may be causing linting issues:
- Use dict[str, Any] instead of complex ContextVar generic
- Remove inline type annotation for variable
- Maintain functionality while fixing lint issues