On Sunday 19 January 2014 10:44:32 Michael Manfre wrote:
> On Sun, Jan 19, 2014 at 5:23 AM, Shai Berger <s...@platonix.com> wrote:
> > Still, spreading with-blocks all over the code for this looks very ugly to
> > me.
> > I'd rather add an execute_single() or execute_and_close() method to the
> > cursors instead. Perhaps even only as private API, as that usage is mostly
> > common within Django's code.
> 
> You would rather deviate from PEP 249 to avoid requiring the users of a
> cursor to explicitly close it? 

No. I'd rather extend the interface defined by PEP 249 in order to reduce the 
amount of RY in the code. Your PR has at least 10 instances of 

        with connection.cursor() as cursor:
                cursor.execute(...)
                # block ends here

and I think around 10 more of variations on the theme

        with connection.cursor() as cursor:
                cursor.execute(...)
                do_something_with(cursor.fetchone())

In similar, though less general fashion, I would add to 
tests/introspection/tests.py a simple module-level function:

def get_table_description(*args):
        with connection.cursor as cursor:
                return connection.introspection.get_table_description(cursor, 
*args)

There are many other instances in the PR where a cursor defined at the with 
statement is used for more than one database command; I see those as net 
improvement.

(I must admit that my initial reaction was "colored" by your other PR[1], 
where these one-line-with-blocks seem to be a larger percentage of the with-
blocks. Still).

Shai.

[1] https://github.com/django/django/pull/2143

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/2404579.hcV3zBsRXv%40deblack.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to