Skip to content

MarathonObject is not hashable in Python3 #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jolynch opened this issue Jun 21, 2017 · 0 comments · Fixed by #204
Closed

MarathonObject is not hashable in Python3 #203

jolynch opened this issue Jun 21, 2017 · 0 comments · Fixed by #204

Comments

@jolynch
Copy link
Contributor

jolynch commented Jun 21, 2017

From what I can tell MarathonObject et al. are basically record types, but they unfortunately don't have a __hash__ method so in Python3 you can no longer put them in dictionaries or sets, for example:

obj = MarathonObject()
collection[obj] = ...

Works fine on Python 2.7 (because it's using literal identity) but Python3 correctly complains since MarathonObject implements __eq__ but not __hash__.

We pretty frequently put MarathonTasks in sets and such to figure out which tasks are running or not in PaaSTA, so ... either we can refactor PaaSTA to actually have a wrapper type around the types that marathon-python is trying to do, or we can define hash on the MarathonObject class.

I think the right answer is that marathon-python should use a proper record type like namedtuple or something really cool like PRecord. The ok answer would be to just define __hash__ to be the hash of the json representation (which is meh because the object can be mutated so the hash could change which is bad).

I don't want to unilaterally add a dependency on pyrsistent, but I really think that a proper record type instead of hand rolled object hierarchies would be much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant