On 11/10/10 07:05, Alex Gaynor wrote:
I think the solution there is something like:

@skipUnless(sys.version>= (2, 5))
def test(self):
     exec """
        from __future__ import with_statement
        with self.assertNumQueries(1):
             Model.objects.get(pk=2)
     """

Not exactly beautiful (in fact it's the exact opposite), but it is functional.

Alex

That does seem slightly hacky, but it's probably the cleanest way there is; the only alternative is executing a with statement inside an exec block and catching the ImportError; I tend to err on the side of testing functionality, not versions.

However, since a SyntaxError is a bit too general, and we know exactly what Python versions support with:, that's not too much of an issue.

I'd be in favour of adding more context managers in, if only as value-added code; as that gist demonstrates, we can use their functionality now, just without the syntactic sugar that "with:" provides, and then when we eliminate 2.4 support, move over to using them internally as well; in the meantime, we bring potential joy and happiness to the significant number of projects which are written only for 2.5 or above.

Andrew

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to