Skip to content

DictLoader

Base classes

Name Children Inherits
LoaderMixin
jinjarope.loaders
Loader mixin which allows to OR loaders into a choice loader.
DictLoader
jinja2.loaders
Loads a template from a Python dict mapping template names to

⋔ Inheritance diagram

graph TD
  94642251671248["loaders.DictLoader"]
  94642250124976["loaders.LoaderMixin"]
  140025743487200["builtins.object"]
  94642249990704["loaders.DictLoader"]
  94642249831088["loaders.BaseLoader"]
  94642250124976 --> 94642251671248
  140025743487200 --> 94642250124976
  94642249990704 --> 94642251671248
  94642249831088 --> 94642249990704
  140025743487200 --> 94642249831088

🛈 DocStrings

Bases: LoaderMixin, DictLoader

A loader to load static content from a path->template-str mapping.

Source code in src/jinjarope/loaders.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
class DictLoader(LoaderMixin, jinja2.DictLoader):
    """A loader to load static content from a path->template-str mapping."""

    ID = "dict"

    def __repr__(self):
        return utils.get_repr(self, mapping=self.mapping)

    def __add__(self, other: dict[str, str] | jinja2.DictLoader) -> DictLoader:
        if isinstance(other, jinja2.DictLoader):
            mapping = {**self.mapping, **other.mapping}
        else:
            mapping = {**self.mapping, **other}
        return DictLoader(mapping)

    def __eq__(self, other):
        return type(self) is type(other) and self.mapping == other.mapping

    def __hash__(self):
        return hash(tuple(sorted(self.mapping.items())))

Show source on GitHub