On 30 août, 11:41, AndyB <[EMAIL PROTECTED]> wrote:
> I read the following snippet with 
> interest:http://www.djangosnippets.org/snippets/1010/
>
> I am trying to lock that tightly into brain as I can imagine being
> tripped up by that and ending up completely confused as to why my code
> doesn't work.

Then you'd be tripped up and ends up completly confused by any raw
python code. Did you ever tried comparing a string and an int in
Python ???

> Does anyone else think that there should be an elegant way to deal
> with comparing different types in a template?

This is already the case : the ifequal tag relies on Python's equality
testing, which is defined by the classes of the two objects to be
compared.

http://docs.python.org/ref/customization.html


> I almost wonder if we
> need to either:
> a) implicitly coerce types

yuck.

> or b) throw an exception (or at least log a warning)

Why so ?

> The current behaviour turns Python into a loosely typed language in
> the worst possible way.

I'm not sure I get your point here... The "current behaviour" of
ifequal is actually the the current behaviour of Python's equality
testing.

 Python 2.5.1 (r251:54863, Apr  6 2008, 17:20:35)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> if "1" == 1: print "never"
...
>>>

Also and FWIW,  the use case (hem...) mentionned in the django-snippet
you linked to is IMHO a design smell. Such a test has nothing to do in
a template.

My 2 cents...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to