Opened 5 years ago

Closed 5 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 Nick Pope, 5 years ago

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...

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: newclosed
Summary: QuerySet could be a collections.abc.SetQuerySet 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.

Note: See TracTickets for help on using tickets.
Back to Top