Question

As I was reading peewee docs, I found a surprising statement:

# python code
messages = Message.select().where(
    Message.user << user.following()
)

Wow, can someone please explain what does that do? I know that << is just a lshift (left shift) operator (which moves the binary representation left for intergers, similar behavior applies to right shift), but I didn't know this can handle lists (user.following() is a list). Is it just operator overloading written by peewee authors or some kind of a python core feature I don't know?

Was it helpful?

Solution

pewee indeed uses operator overloading, in this case with the __lshift__ magic method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top