]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add __hash__ to Locale.
authorRoy Wellington Ⅳ <roy@mybasis.com>
Tue, 31 Mar 2015 21:44:10 +0000 (14:44 -0700)
committerAarni Koskela <akx@iki.fi>
Tue, 29 Dec 2015 15:55:29 +0000 (17:55 +0200)
babel/core.py
tests/test_core.py

index 84ee1892012e4fcbf7479aeefef598337b75b4d2..2df139c2c79d08feeef8fe7bc79aecf3eb66577e 100644 (file)
@@ -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'):
index 4ce92ddbc6fa2d11b0ff74002ba34c495f03c584..c887d5f53486a90c6e3ab159183a2bf0b6ccbb80 100644 (file)
@@ -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')"