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

multistring needs a __hash__ method #3434

Closed
phlax opened this issue Apr 26, 2016 · 5 comments
Closed

multistring needs a __hash__ method #3434

phlax opened this issue Apr 26, 2016 · 5 comments
Milestone

Comments

@phlax
Copy link
Member

phlax commented Apr 26, 2016

In old ttk you could do something like

foo = multistring("foo")
foodict = {foo: "bar"}
assert 'foo' in foodict

It seems this no longer works - not sure why, but a __hash__ method that returns hash(str(self)) should fix the problem i believe

@claudep @julen any thoughts on this?

@unho unho added this to the 2.0 milestone Apr 26, 2016
@julen
Copy link
Contributor

julen commented Apr 26, 2016

FWIW multistring already has as __hash__ method.

Also, I don't see any differences across versions with the snippet you provided:

In [1]: from translate import __version__
In [2]: __version__.sver
Out[2]: '1.13.0'
In [3]: from translate.misc.multistring import multistring
In [4]: foo = multistring('foo')
In [5]: foodict = { foo: 'bar' }
In [6]: assert 'foo' in foodict
In [1]: from translate import __version__
In [2]: __version__.sver
Out[2]: '1.14.0-rc1'
In [3]: from translate.misc.multistring import multistring
In [4]: foo = multistring('foo')
In [5]: foodict = { foo: 'bar' }
In [6]: assert 'foo' in foodict

@phlax
Copy link
Member Author

phlax commented Apr 26, 2016

@julen i think i may have got this the wrong way round it shoud read

foo = multistring("foo")
foodict = {"foo": "bar"}
assert foo in foodict

@julen
Copy link
Contributor

julen commented Apr 26, 2016

WFM.

phlax added a commit to phlax/translate that referenced this issue Apr 26, 2016
Previously you were able to do `str in dict_with_multistring_key`
and because the str and multistring hashes matched it would find
the dict element.

This test demonstrates that this is no longer possible.

ref translate#3434
@phlax
Copy link
Member Author

phlax commented Apr 26, 2016

WFM

not sure if you mean code or test @julen

ive added a PR to demonstrate the problem and fix it

@phlax
Copy link
Member Author

phlax commented Apr 26, 2016

for ref here is the test failing https://travis-ci.org/phlax/translate/jobs/125898982#L1126

@phlax phlax closed this as completed in de62b61 Apr 27, 2016
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

3 participants