Skip to content

EAFP in pystache.context:_get_value to support defaultdicts #188

@Lucas-C

Description

@Lucas-C

Hi,

Following the "it's Easier to Ask Forgiveness than Permission" principle, is it possible to modify 2 lines in
pystache.context:_get_value ?

    if isinstance(context, dict):
        try:
            return context[key]
        except KeyError:
            pass

This would make it possible to pass a collections.defaultdict to pystache.render, which does not work currently:

pystache.render("Hello {{}} !", defaultdict(lambda: "Anonymous visitor"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions