This might sound like a weird question and and most likely has no practical relevance but that said, I came around a (to me) strange behavior in python.
If I have a simple class that overrides the __gt__
method like this
class K:
def __init__(self, names):
if isinstance(names, list):
self.names = names
else:
self.names = [names]
def __gt__(self, other):
assert isinstance(other, K)
return K(self.names + other.names)
then I was thinking the following
print((K("a") > K("b") > K("c")).names)
should result n
['a', 'b', 'c']
but instead I get
['b', 'c']
if I do
print(((K("a") > K("b")) > K("c")).names)
it works but without the additional brackets the first statement seems to have disappeared somehow.
There is certainly something about the __gt__
method I do not quite understand correctly, can you pleas explain what I'm missing and why this is not working in the way I suspected.