Re: __contains__ classmethod?

2017-12-18 Thread MRAB
On 2017-12-18 21:25, Tim Chase wrote: Playing around, I had this (happens to be Py2, but gets the same result in Py3) code class X(object): ONE = "one" TWO = "two" _ALL = frozenset(v for k,v in locals().items() if k.isupper()) @classmethod def __contains__(cls, v): return v i

Re: __contains__ classmethod?

2017-12-18 Thread Peter Otten
Peter Otten wrote: > Tim Chase wrote: > >> Playing around, I had this (happens to be Py2, but gets the same >> result in Py3) code >> >> class X(object): >> ONE = "one" >> TWO = "two" >> _ALL = frozenset(v for k,v in locals().items() if k.isupper()) >> @classmethod >> def __contains__(

Re: __contains__ classmethod?

2017-12-18 Thread Random832
On Mon, Dec 18, 2017, at 16:25, Tim Chase wrote: > My understanding was that "in" makes use of an available __contains__ > but something seems to preventing Python from finding that. > > What's going on here? Most __ methods have to be an actual method on the class object, which means you have to

Re: __contains__ classmethod?

2017-12-18 Thread Peter Otten
Tim Chase wrote: > Playing around, I had this (happens to be Py2, but gets the same > result in Py3) code > > class X(object): > ONE = "one" > TWO = "two" > _ALL = frozenset(v for k,v in locals().items() if k.isupper()) > @classmethod > def __contains__(cls, v): > return v in cls._A

__contains__ classmethod?

2017-12-18 Thread Tim Chase
Playing around, I had this (happens to be Py2, but gets the same result in Py3) code class X(object): ONE = "one" TWO = "two" _ALL = frozenset(v for k,v in locals().items() if k.isupper()) @classmethod def __contains__(cls, v): return v in cls._ALL print(dir(X)) print(X._ALL) Runnin