-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fields are not hashable in Python 3 #36
Comments
Completely untested:
|
Python 3 makes classes unhashable if they implement |
I'm -1 for (Which is status quo on Python 2, but I'd prefer to view it as an unfixed bug.) |
I agree that the correct solution needs to implement a hash based on an immutable subset of the equality criteria implemented by But such a hash would mean a backwards-incompatible change: for example, code that uses fields as dict keys may rely on mixing fields from different schemas that are not identical but compare as equal otherwise. Therefore, I suggest going with the status quo for now, i.e. using |
@mgedmin wrote:
I agree, and so does the language spec:
Currently that property is broken. Any code that is trying to hash schema fields is therefore likely to also be subtly broken. I'm -1 on enshrining |
Technically, an alternative would be to fall back to the inherited hash implementation in Python 2, and use |
They use a defined hashing algorithm that matches what equality does on all versions of Python. Previously, on Python 2, fields were hashed based on their identity. This violated the rule that equal objects should have equal hashes, and now they do. Since having equal hashes does not imply that the objects are equal, this is not expected to be a compatibility problem. Included tests with a dict show that there shouldn't be false matches even with equal hashes. Fixes #36
If that's an important use case, then it seems to me the fix is to include I don't know if that's an important use case, though. The fields would have to have identical title and description strings, default and missing values, readonly and required status, plus whatever is field-specific. The strings, especially seem unlikely to match. One would probably have to be using the identical field instance and assigning it in different interfaces for that to happen, which is pretty weird because it resets |
I opened #40 to discuss whether |
There is a inconsistency that breaks caching schema-fields in Plone with memoize. What do we need to change to make field instances hashable?
Python2:
Python 3:
Here is the original traceback from Plone 5.2 with Python 3 when opening http://0.0.0.0:6543/Plone/dexterity-types/Document/@@fields:
The text was updated successfully, but these errors were encountered: