Skip to content

Commit

Permalink
Add __hash__ to Locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Wellington Ⅳ authored and akx committed Dec 29, 2015
1 parent 5d0c4ef commit 2aa8074
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions babel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)

def __hash__(self):
return hash((self.language, self.territory, self.script, self.variant))

def __repr__(self):
parameters = ['']
for key in ('territory', 'script', 'variant'):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def test_get_global():

class TestLocaleClass:

def test_hash(self):
locale_a = Locale('en', 'US')
locale_b = Locale('en', 'US')
assert hash(locale_a) == hash(locale_b)

def test_repr(self):
assert repr(Locale('en', 'US')) == "Locale('en', territory='US')"

Expand Down

1 comment on commit 2aa8074

@sils
Copy link
Member

@sils sils commented on 2aa8074 Dec 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.