A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-January/076401.html below:

[Python-Dev] misbehaving __contains__

[Python-Dev] misbehaving __contains__ [Python-Dev] misbehaving __contains__Daniel Stutzbach daniel at stutzbachenterprises.com
Wed Jan 23 00:46:48 CET 2008
On Jan 22, 2008 1:26 PM, tomer filiba <tomerfiliba at gmail.com> wrote:
> >>> class Foo(object):
> ...     def __contains__(self, key):
> ...             return 17
> ...     def __eq__(self, other):
> ...             return 19
> ...
> >>>
> >>> f=Foo()
> >>> f == 8
> 19
> >>> 8 in f
> True

There are many places in the C implementation where a slot returns an
int rather than a PyObject.  There other replies in this thread seem
to support altering the signature of the slot to return a PyObject.
Is this setting a precedent that _all_ slots should return a PyObject?

Consider the following third behavior:

>>> class foo(object):
...     def __len__(self):
...             return 'foo'
...
>>> x = foo()
>>> len(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

-- 
Daniel Stutzbach, Ph.D.             President, Stutzbach Enterprises LLC
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4