Skip to content
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

Pred hashing not consistent with Pred equality #107

Closed
goodmami opened this issue May 9, 2017 · 0 comments
Closed

Pred hashing not consistent with Pred equality #107

goodmami opened this issue May 9, 2017 · 0 comments
Milestone

Comments

@goodmami
Copy link
Member

goodmami commented May 9, 2017

The Pred component class compares with strings that may or may not end in _rel:

>>> p = Pred.stringpred('udef_q_rel')
>>> p == 'udef_q'
True
>>> p == 'udef_q_rel'
True
>>> p == '_udef_q'
False
>>> p == 'udef'
False

But this does not work with hashing (e.g. in a dict or set):

>>> Pred.stringpred('udef_q') in set(['udef_q', 'proper_q'])
True
>>> Pred.stringpred('udef_q_rel') in set(['udef_q', 'proper_q'])
False
>>> Pred.stringpred('udef_q') in set(['udef_q_rel', 'proper_q'])
False
>>> Pred.stringpred('udef_q') in set([Pred.stringpred('udef_q_rel'), Pred.stringpred('proper_q')])
False
>>> 'udef_q' in set([Pred.stringpred('udef_q_rel'), Pred.stringpred('proper_q')])
False
>>> 'udef_q_rel' in set([Pred.stringpred('udef_q_rel'), Pred.stringpred('proper_q')])
True
>>> any(Pred.stringpred('udef_q_rel') == q for q in set(['udef_q', 'proper_q']))
True

Hashing consistently on the short form would help when a Pred object is checked against Pred objects in a hash, but not when strings are used. I can't think of a good way around the latter issue, so maybe some documentation needs to be written about that.

@goodmami goodmami modified the milestone: v0.6.2 May 31, 2017
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

No branches or pull requests

1 participant