mako icon indicating copy to clipboard operation
mako copied to clipboard

emit warning when a block or def is named "body"

Open sqlalchemy-bot opened this issue 7 years ago • 4 comments

Migrated issue, originally created by Bérenger Enselme (@benselme)

This is using CPython 3.6.1

from mako.template import Template

if __name__ == '__main__':
    s = Template("""aaaa<%block name="bodi"></%block>bbbb""").render()
    assert s == 'aaaabbbb'  # success
    s = Template("""aaaa<%block name="body"></%block>bbbb""").render()
    assert s == 'aaaabbbb'  # failure, s == '\n '

sqlalchemy-bot avatar May 19 '17 16:05 sqlalchemy-bot

Michael Bayer (@zzzeek) wrote:

this is expected behavior. "body" is a pre-existing name with special behavior and is documented here. It is possible people use it as a "block" name intentionally.

sqlalchemy-bot avatar May 19 '17 18:05 sqlalchemy-bot

Bérenger Enselme (@benselme) wrote:

Thanks, I get it now. I was aware of the body() function but it was not obvious at all that naming a block "body" would overwrite it.

sqlalchemy-bot avatar May 19 '17 19:05 sqlalchemy-bot

Changes by Bérenger Enselme (@benselme):

  • edited description

sqlalchemy-bot avatar May 19 '17 16:05 sqlalchemy-bot

Changes by Michael Bayer (@zzzeek):

  • changed title from "Blank output when there is a block named "body"" to "emit warning when a block or def is named "body""

sqlalchemy-bot avatar May 19 '17 18:05 sqlalchemy-bot