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
  97041655407760["loaders.DictLoader"]
  97041656291584["loaders.LoaderMixin"]
  128674497047040["builtins.object"]
  97041654594720["loaders.DictLoader"]
  97041655470432["loaders.BaseLoader"]
  97041656291584 --> 97041655407760
  128674497047040 --> 97041656291584
  97041654594720 --> 97041655407760
  97041655470432 --> 97041654594720
  128674497047040 --> 97041655470432

🛈 DocStrings

Bases: LoaderMixin, DictLoader

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

Source code in src/jinjarope/loaders.py
class DictLoader(LoaderMixin, jinja2.DictLoader):
    """A loader to load static content from a path->template-str mapping."""

    ID = "dict"

    def __repr__(self) -> str:
        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: object) -> bool:
        if not isinstance(other, DictLoader):
            return NotImplemented
        return self.mapping == other.mapping

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

:fa-brands-github: Show source on GitHub