From 4e51b34b5314a01cf710eeee1ac351455247891e Mon Sep 17 00:00:00 2001 From: blag Date: Wed, 11 Jun 2025 21:41:52 -0600 Subject: [PATCH] Add type hints to loader --- dbtemplates/loader.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 32aad54..a1a9942 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -1,3 +1,5 @@ +from typing import Optional, Tuple + from django.contrib.sites.models import Site from django.db import router from django.template import Origin, TemplateDoesNotExist @@ -31,17 +33,17 @@ class Loader(BaseLoader): loader=self, ) - def get_contents(self, origin): + def get_contents(self, origin: Origin) -> str: content, _ = self._load_template_source(origin.template_name) return content - def _load_and_store_template(self, template_name, cache_key, site, **params): + def _load_and_store_template(self, template_name: str, cache_key: str, site: Site, **params) -> Tuple[str, str]: template = Template.objects.get(name__exact=template_name, **params) db = router.db_for_read(Template, instance=template) display_name = f"dbtemplates:{db}:{template_name}:{site.domain}" return set_and_return(cache_key, template.content, display_name) - def _load_template_source(self, template_name, template_dirs=None): + def _load_template_source(self, template_name: str, template_dirs: Optional[str] = None) -> Tuple[str, str]: # The logic should work like this: # * Try to find the template in the cache. If found, return it. # * Now check the cache if a lookup for the given template