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
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__(
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
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
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