Repository: mlenzen/collections-extended

Issue:
bijection.__init__ tuples need to be len == 2

Discussion:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index c371394..ac95bf9 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -34,6 +34,8 @@ Added
 Fixed
 """""
 
+* tuples passed to the bijection constructor must have len == 2, not >= 2
+
 Deprecated
 """"""""""
 
diff --git a/collections_extended/bijection.py b/collections_extended/bijection.py
index 5547bf6..591216a 100644
--- a/collections_extended/bijection.py
+++ b/collections_extended/bijection.py
@@ -25,7 +25,8 @@ class bijection(MutableMapping):
 					self[key] = value
 			else:
 				for pair in iterable:
-					self[pair[0]] = pair[1]
+					key, value = pair
+					self[key] = value
 		for key, value in kwarg.items():
 			self[key] = value
 


Test patch:
diff --git a/tests/test_bijection.py b/tests/test_bijection.py
index 576cd77..48af061 100644
--- a/tests/test_bijection.py
+++ b/tests/test_bijection.py
@@ -34,6 +34,11 @@ def test_init_from_pairs():
 	assert bijection({'a': 1, 'b': 2}) == bijection((('a', 1), ('b', 2)))
 
 
+def test_init_from_triples_fails():
+	with pytest.raises(ValueError):
+		bijection((('a', 1, 0), ('b', 2, 0), ))
+
+
 def test_repr():
 	"""Test __repr__."""
 	b = bijection()