Py2D
Py2D copied to clipboard
Polygon.__eq__ and dictionary
Sometimes eq function works incorrect if Polygon uses as dictionary key. "if my_poly in my_dict.keys()" returns True, but when I try to get "my_val = my_dict[my_poly]" it causes KeyError Exeption. I deleted eq function in my code to workaround this.
I looked into this, and on python3 I get unhashable type: 'Polygon'.
Then I thought about implementing a __hash__ method, and realized that since Polygons are mutable, they really shouldn't be hashable. If I were you I'd look into a different way to organize data in your application, or you could make an immutable object with an interface to Polygon.