ws6079
ws6079

Reputation: 343

Implementing intersection operator for a set-like class in Python

I'm trying to implement a wrapper class which should ideally allow me to get the intersection of its elements using the notation:

a & b

Is there a specific method that I can implement to achieve this? (I know that the individual elements need to implement the __hash__ and __eq__ methods)

I'm currently getting the following error:

TypeError: unsupported operand type(s) for &: 'PropArray' and 'PropArray'

Upvotes: 2

Views: 538

Answers (1)

Benjamin
Benjamin

Reputation: 3477

Try to override:

def __and__(self, *args, **kwargs): # real signature unknown
    """ Return self&value. """
    pass

in your class

Upvotes: 2

Related Questions