[Django] #31561: QuerySet could be a collections.abc.Set

12 views
Skip to first unread message

Django

unread,
May 10, 2020, 2:44:36 AM5/10/20
to django-...@googlegroups.com
#31561: QuerySet could be a collections.abc.Set
-------------------------------------+-------------------------------------
Reporter: yahya- | Owner: nobody
abou-imran |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I don’t know if it’s intended, but `QuerySet` doesn’t inherit from
`collections.abc.Set` although it implements its full API.
The only missing methods is `__contains__` but the `in` is working anyway,
fall-backing to the iteration protocol (through `__iter__`).

Pass it to the `Set.register` could also be considered.

I’m not sure if there is a clear win to this, or if it could include some
non desired behaviors (like the possibility of unions with other `Set`
types).

From a theoretical point of view it’s seems pretty logic – it’s called
“Query**Set**” by the way! –, however since `practicality beats purity`…

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

Django

unread,
May 10, 2020, 3:14:28 PM5/10/20
to django-...@googlegroups.com
#31561: QuerySet could be a collections.abc.Set
-------------------------------------+-------------------------------------
Reporter: Alexandre Poitevin | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Nick Pope):

I'm not sure that `collections.abc.Set` is the right abstract base class
as it make no guarantee about order. A `QuerySet` is not equivalent to a
`set`. Even `collections.abc.Sequence` is no good as that inherits from
`collections.abc.Reversible` and `QuerySet` is not reversible. The best we
could probably do is `collections.abc.Collection`...

--
Ticket URL: <https://code.djangoproject.com/ticket/31561#comment:1>

Django

unread,
May 11, 2020, 12:05:23 AM5/11/20
to django-...@googlegroups.com
#31561: QuerySet could be a collections.abc.Set.

-------------------------------------+-------------------------------------
Reporter: Alexandre Poitevin | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix


Comment:

I don't see any benefits of inheriting from `collections.abc` in this
case, and as Nick said, `QuerySet` is not a `set`. You can start a
discussion on DevelopersMailingList if you don't agree.

--
Ticket URL: <https://code.djangoproject.com/ticket/31561#comment:2>

Reply all
Reply to author
Forward
0 new messages