[Python-ideas] Non-boolean return from contains (original) (raw)
Mathias Panzenböck grosser.meister.morti at gmx.net
Tue Jul 27 16:29:56 CEST 2010
- Previous message: [Python-ideas] Non-boolean return from __contains__
- Next message: [Python-ideas] Non-boolean return from __contains__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 07/26/2010 04:20 AM, Alex Gaynor wrote:
Fundamentally the argument in favor of it is the same as for the other comparison operators: you want to do symbolic manipulation using the "normal" syntax, as a DSL. My example is that of a SQL expression builder: SQLAlchemy uses User.id == 3 to create a clause where the ID is 3, but for "id in [1, 2, 3]" it has: User.id.in([1, 2, 3]), which is rather unseamly IMO (at least as much as having User.id.eq(3) would be).
This is a bad example for your wish because this code:
id in [1, 2, 3]
translates into:
[1, 2, 3].contains(id)
So it doesn't help that 'in' may return something else than a bool because the method is called on the wrong object for your purposes.
-panzi
- Previous message: [Python-ideas] Non-boolean return from __contains__
- Next message: [Python-ideas] Non-boolean return from __contains__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]