Discussion:
'dict' is a lambda in templates?
Eli Stevens (Gmail)
2014-06-26 17:39:09 UTC
Permalink
I just tried to use isinstance(myvar, dict) in a template, but got the
following exception:

TypeError: isinstance() arg 2 must be a class, type, or tuple of
classes and types

I got the repr(dict) and it said it was a lambda. Putting in the following:

<py:with vars="content_str = inspect.getsource(dict);">
${content_str}

I get the output from content_str:

'dict': lambda **kw: kw,

I feel fairly confident that this isn't due to anything I've written
directly, but haven't been able to rule out flask or the rest of the
stack I'm using.

Is this a known genshi-ism? Any idea why this would be useful?

For the record (and future searchers), isinstance(myvar, type({})
works well enough, though

Thanks,
Eli
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/d/optout.
Simon Cross
2014-06-30 08:32:29 UTC
Permalink
For me:

from genshi.template.markup import MarkupTemplate

t = MarkupTemplate("""<div>${isinstance(x, dict)}</div>""")

print t.generate(x=1).render()
print t.generate(x={}).render()

prints:

<div>False</div>
<div>True</div>

So it doesn't look like Genshi doesn't do anything odd.

Schiavo
Simon
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/d/optout.
Loading...