From: Roy Wellington Ⅳ Date: Tue, 31 Mar 2015 21:44:10 +0000 (-0700) Subject: Add __hash__ to Locale. X-Git-Tag: 2.2.0~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aa80748f6123aa95f752353263c6ca2567b735e;p=thirdparty%2Fbabel.git Add __hash__ to Locale. --- diff --git a/babel/core.py b/babel/core.py index 84ee1892..2df139c2 100644 --- a/babel/core.py +++ b/babel/core.py @@ -326,6 +326,9 @@ class Locale(object): 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'): diff --git a/tests/test_core.py b/tests/test_core.py index 4ce92ddb..c887d5f5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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')"