#35154: QuerySet implements `contains` but not `__contains__` -------------------------------------+------------------------------------- Reporter: fidoriel | Owner: nobody Type: New feature | Status: closed Component: Database layer | Version: 5.0 (models, ORM) | Severity: Normal | Resolution: wontfix Keywords: queryset contains | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Mariusz Felisiak):
* status: new => closed * type: Uncategorized => New feature * resolution: => wontfix Old description: > This is a similar proposal to > https://code.djangoproject.com/ticket/31561, but it is not the same. > Currently using > {{{ > x in myQuerySet > }}} > results in python using the fallback solution: > https://docs.python.org/3/reference/expressions.html#membership-test- > details > Because https://groups.google.com/g/django- > developers/c/NZaMq9BALrs/m/OCNTh6QyCAAJ deiced to implement contains in > https://code.djangoproject.com/ticket/24141 > I think it is only consistent to have the same behavior implemented in > __contains__. I would expect that, it is also a more efficient > implementation and unifies django behavior. Nevertheless, documentation > is needed why this inconsistency exists. I was not able to find a reason. > Because the mailing list agreed on adding contains, this is discussed > behavior. Why was __contains__ not added in the first place? To not have > breaking changes? I cannot see what would break. > > As said in https://code.djangoproject.com/ticket/31561 a queryset could > be a collection to make typing easier. But this is not the intention of > this issue. New description: This is a similar proposal to https://code.djangoproject.com/ticket/31561, but it is not the same. Currently using {{{ x in myQuerySet }}} results in python using the fallback solution: https://docs.python.org/3/reference/expressions.html#membership-test- details Because https://groups.google.com/g/django- developers/c/NZaMq9BALrs/m/OCNTh6QyCAAJ deiced to implement contains in https://code.djangoproject.com/ticket/24141 I think it is only consistent to have the same behavior implemented in `__contains__`. I would expect that, it is also a more efficient implementation and unifies django behavior. Nevertheless, documentation is needed why this inconsistency exists. I was not able to find a reason. Because the mailing list agreed on adding contains, this is discussed behavior. Why was `__contains__` not added in the first place? To not have breaking changes? I cannot see what would break. As said in https://code.djangoproject.com/ticket/31561 a queryset could be a collection to make typing easier. But this is not the intention of this issue. -- Comment: > Why was `__contains__` not added in the first place? Have you read the discussion that you mention in the ticket? or comments in #24141? The entire discussion is about `__contains__` and there was a consensus to add `contains()` instead. -- Ticket URL: <https://code.djangoproject.com/ticket/35154#comment:1> 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018d594e4980-50adc9ea-fd15-4c41-9d92-4c6f466187c5-000000%40eu-central-1.amazonses.com.