-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
error of unhashable type #259
Comments
Root cause is this:
failing with:
|
There seems to be the opinion in the java community, that .hashCode implementations should never throw exceptions. |
But this seem to be a very special case in Python, where a python type is not hashable. |
Interesting. I can tell you that the user interface philosophy so far as been:
This is the first time I'm aware of that there has been a conflict with a Java idiom. For instance, The simple approach would be to patch the hashing behavior for Java, so maybe that's best. I don't think many libpython-clj users would be overly upset that calling hash on an unhashable object would return nil rather than throw an error. |
Hmm. Or embrace and extend the python dict type somehow to support clojure's algorithm for hashing. |
I think return 0 is as well acceptable for a java hashcode impl (better the nil) |
There are some reports that Clerk cannot render the "newsgroup" objects, no sure if same reason. |
Maybe the code here:
should catch Just to address the point that "non hashable" in python is "expected", while in java its not. |
As a hacker, I would love this approach and I think it would fulfill the original intent of introspectable datastructures. Less hacker-inclined devs may fume a bit at the potential implications of sets of mutable dicts and dicts as keys, and other potential footguns. Not sure what the effort would be to make this behavior opt-in or toggle-able. |
As a far simpler example, we can take this for discussion: (hash
(py/->py-dict {:a 1})) This should NOT fail in my view, but it does:
|
In my view, in the same way we have a default behavoiur for toString:
which should return "a string" for any libpython object, we should return "a number " for any libpython object, when .hashCode is called on it. Which algorithm to use to calculate the hashcode is then a less important consideration. |
Well this discussion has also inspired me to open a new issue, because analytically I think a very important tool that is currently missing is the equivalent of the issue with str, @behrica , is that Python objects are free to implement (or not) their own str implementation, and there would be a lot of unhelpful and borderline random behavior using str as a hashing key. |
I am not suggesting to use str as hashing key.
and either: Both will comply with the hashcode/equals rules of Java, I believe: |
Or check here:
if the python object is hashable:
|
This issue makes Clerk and libpython-clj not work well together. |
Doing this
and teh opening
newsgroups
i te ccider-inspector
gives an errorSeems to happen only in
cider-inspector
...The text was updated successfully, but these errors were encountered: