Opened 6 years ago
Closed 6 years ago
#31561 closed Cleanup/optimization (wontfix)
QuerySet could be a collections.abc.Set.
| Reported by: | Alexandre Poitevin | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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 “QuerySet” by the way! –, however since practicality beats purity…
Change History (2)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
| Summary: | QuerySet could be a collections.abc.Set → QuerySet could be a collections.abc.Set. |
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.
I'm not sure that
collections.abc.Setis the right abstract base class as it make no guarantee about order. AQuerySetis not equivalent to aset. Evencollections.abc.Sequenceis no good as that inherits fromcollections.abc.ReversibleandQuerySetis not reversible. The best we could probably do iscollections.abc.Collection...