From 2aa80748f6123aa95f752353263c6ca2567b735e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roy=20Wellington=20=E2=85=A3?= Date: Tue, 31 Mar 2015 14:44:10 -0700 Subject: [PATCH] Add __hash__ to Locale. --- babel/core.py | 3 +++ tests/test_core.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/babel/core.py b/babel/core.py index 84ee18920..2df139c2c 100644 --- a/babel/core.py +++ b/babel/core.py @@ -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'): diff --git a/tests/test_core.py b/tests/test_core.py index 4ce92ddbc..c887d5f53 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')"