Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43926

Re: Feature Request: `operator.not_in`

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'operator': 0.03; 'definitions.': 0.07; 'method.': 0.07; 'skip:` 10': 0.07; '*is*': 0.09; 'arrays': 0.09; 'currently,': 0.09; 'differently.': 0.09; 'implements': 0.09; 'imply': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; 'behave': 0.16; 'boolean': 0.16; 'inverse': 0.16; 'item)': 0.16; 'magic': 0.16; 'operator.': 0.16; 'operators.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:`': 0.16; 'two,': 0.16; 'which,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'translated': 0.19; 'fit': 0.20; 'seems': 0.21; 'appears': 0.22; 'manual': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'exists': 0.24; 'mathematical': 0.24; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'leave': 0.29; '(this': 0.29; 'am,': 0.29; 'membership': 0.31; 'operators': 0.31; '"the': 0.34; 'skip:_ 10': 0.34; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'method': 0.36; 'should': 0.36; 'expected': 0.38; 'implement': 0.38; 'represent': 0.38; 'skip:o 20': 0.38; 'rich': 0.38; 'whatever': 0.38; 'to:addr :python-list': 0.38; 'little': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'details.': 0.61; 'received:173': 0.61; 'more': 0.64; 'believe': 0.68; 'special': 0.74; 'believe,': 0.84; 'received:fios.verizon.net': 0.84; 'subject:skip:o 10': 0.84; 'tricky': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Jan Reedy <tjreedy@udel.edu>
Subject Re: Feature Request: `operator.not_in`
Date Fri, 19 Apr 2013 14:27:49 -0400
References <5171543D.708@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
In-Reply-To <5171543D.708@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.837.1366396079.3114.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366396079 news.xs4all.nl 2296 [2001:888:2000:d::a6]:52055
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43926

Show key headers only | View raw


On 4/19/2013 10:27 AM, Matthew Gilson wrote:
) It seems to me that the operator module should have a `not_in` or
> `not_contains` function.  It seems asymmetric that there exists a
> `is_not` function which implements `x is not y` but there isn't a
> function to represent `x not in y`.

There is also no operator.in.
There is operator.contains and operator.__contains__.
There is no operator.not_contains because there is no __not_contains__ 
special method. (Your point two, which I disagree with.)

> 2) I suspect this one might be a little more controversial, but it seems
> to me that there should be a separate magic method bound to the `not in`
> operator.

The reference manual disagrees.
"The operator not in is defined to have the inverse true value of in."

>  Currently, when inspecting the bytecode, it appears to me
> that `not x in y` is translated to `x not in y` (this supports item 1
> slightly).  However, I don't believe this should be the case.  In
> python, `x < y` does not imply `not x >= y` because a custom object can
> do whatever it wants with `__ge__` and `__lt__` -- They don't have to
> fit the normal mathematical definitions.

The reason for this is that the rich comparisons do not have to return 
boolean values, and do not for numarray arrays which, I believe, 
implement the operators itemwise.

 > I don't see any reason why containment should behave differently.

'Design by analogy' is tricky because analogies often leave out 
important details. __contains__ *is* expected to return true/false.

" object.__contains__(self, item)
     Called to implement membership test operators. Should return true 
if item is in self, false otherwise"

--
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Feature Request: `operator.not_in` Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-19 14:27 -0400

csiph-web