Py2D icon indicating copy to clipboard operation
Py2D copied to clipboard

Polygon.__eq__ and dictionary

Open 09th opened this issue 12 years ago • 1 comments

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.

09th avatar Dec 05 '13 15:12 09th

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.

hsharrison avatar Jan 21 '14 02:01 hsharrison