Refactor endpoint caching to be explicit and typed#700
Conversation
Replaced implicit `_cache_name` string property and dynamic `getattr`/`setattr` with explicit `_enable_cache` boolean and typed `_cache` attribute. Updated `GenericEndpoint`, `CacheMixin`, `EndpointABC`, `EndpointProtocol` and all cached endpoints (`FormsEndpoint`, `StudiesEndpoint`, `VariablesEndpoint`, `IntervalsEndpoint`). This improves type safety, reduces cognitive load, and eliminates "magic" string dependencies. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Removed `typing.Optional` from `imednet/core/endpoint/abc.py` and `imednet/core/endpoint/protocols.py` as it became redundant after replacing `_cache_name: Optional[str]` with `_enable_cache: bool`. Fixes CI linting failures (F401). Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Refactored the caching mechanism in the endpoint classes to address "Primitive Obsession" and "Implicit vs Explicit" architectural smells.
Key changes:
_cache_nameproperty fromEndpointABCandGenericEndpoint._enable_cacheboolean flag toEndpointABC(default False)._cacheattribute toGenericEndpoint, strictly typed asOptional[Union[List[T], Dict[str, List[T]]]].GenericEndpoint.__init__to initialize_cacheexplicitly based on_enable_cacheandrequires_study_key.CacheMixinto useself._cachedirectly instead of dynamic attribute access.FormsEndpoint,StudiesEndpoint,VariablesEndpoint, andIntervalsEndpointto set_enable_cache = Trueinstead of defining_cache_name.EndpointProtocolto reflect these changes.Verification:
test_studies_endpoint.py,test_forms_endpoint.py, etc.) which explicitly test caching behavior.PR created automatically by Jules for task 5961568543587308941 started by @fderuiter