Skip to content

template renderer renders properties strangely #120

@granders

Description

@granders

Refactoring a field into a property can lead to surprising results when rendering

class C(TemplateRenderer):
  x = 2

class D(TemplateRenderer):
  @property
  def x(self):
    return 2

c = C()
d = D()
c.render_template("{{x}}")  # "2"
d.render_template("{[x}}")  # "<property ob... 0x101300e68>"

Cause: @propertys show up in the class dict as a property object, but not in the instance dict, and TemplateRenderer uses these dicts when rendering. So the computed property value isn't visible to the render method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions