#22531: Q objects lack a useful repr
----------------------------------------------+--------------------
     Reporter:  Keryn Knight <django@…>       |      Owner:  nobody
         Type:  New feature                   |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  master
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 {{{
 >>> from django.db.models.query_utils import Q
 >>> a = Q()
 >>> b = Q(a=1, b=2)
 >>> c = b & Q(c=3)
 >>> d = c | Q(d=4)
 >>> e = Q(d) & Q(e=5)
 >>> f = e | ~Q(f=6)
 >>> repr(f)  # actually just typing f<enter> into ipython/pdb/python REPL
 '<django.db.models.query_utils.Q at 0x103184050>'
 }}}
 That's not exactly useful, given a Q object may represent a complex tree.
 As it turns out, Q objects '''do''' implement str, which is the SQL output
 for the Node subclass, which would be more useful than the above repr, and
 possibly more useful than the nested repr of .children

 The simplest repr implementation would probably be something like:

 {{{
 def __repr__(self):
     return '{obj.__class__!r} {obj!s}'.format(obj=self)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22531>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to