[Python-ideas] add __contains__ into the "type" object

Pavol Lisy pavol.lisy at gmail.com
Sat Mar 4 06:52:19 EST 2017


On 3/2/17, Stephan Houben <stephanh42 at gmail.com> wrote:
> A crucial difference between a set and a type is that you cannot
> explicitly iterate over the elements of a type, so while we could implement
>
> x in int
>
> to do something useful, we cannot make
>
> for x in int:
>    print(x)
>
> Because if we could, we could implement Russell's paradox in Python:
>
> R = set(x for x in object if x not in x)
>
> print(R in R)
>
> Bottom line: a set is not a type, even in mathematics.
>
> Stephan

:)

Problem of Russel paradox was that set was defined intuitively in that time.

And it is why **class**, was introduced in set theory then! :)

In set theory you could ask if x member of set or x is member of class
and difference between set and class is just that set is not same as
class. (class is some intuitively defined concept just to avoid
paradoxes like Russel's)

And python does not implement platonism
(https://en.wikipedia.org/wiki/Philosophy_of_mathematics#Platonism) -
object doesn't exists until they are created.

class int is not infinite in its actuality. (Does not occupy infinite memory)

So I think that print(R in R) would print True. Because in the time
set is in creation process this object (set) is not member of that set
so it would be added to that set.

Or maybe it will return False if this incomplete set is not evaluated
in process of its creation.

It is matter of implementation, but it could be perfectly deterministic.

So maybe Russel had to "implement" GIL in mathematics ;)

In current python you could ask about "membership" (operator in) where
object is not set:

    if 3 in itertools.count():  # this is ok
        type(itertools.count())  # this is ok
    else:
        set(itertools.count())   # I don't approve this :P

python set is not mathematics set too:

    a = set()
    a.add(a)  # TypeError: unhashable type: 'set'

I am -1 about proposal in this moment. I probably understand
motivation but I don't see yet that this change could bring enough
goodness.


More information about the Python-ideas mailing list