Commits

Hong Minhee committed 5d41778

Fixed #2

Comments (0)

Files changed (2)

     def __call__(self, function):
         generic_method = self.generic_method
         if function is generic_method:
-            function = generic_method.latest_added_function
+            function = generic_method.latest_added_function[1]
         generic_method[self.cls] = self.with_receiver, function
         return generic_method
 

typequery_tests.py

         return 'dict ' + repr(value)
     assert im2({}) == 'dict {}'  # cache invalidation
 
+
+def test_issue_2():
+    """Regression test for `issue #2`__: multiple type handling with option
+    raises error.
+
+    __ https://bitbucket.org/dahlia/typequery/issue/2/multiple-type-handling-with-option-raises
+
+    """
+    amp = GenericMethod('amp')
+    @amp.of(int)
+    @amp.of(float)
+    def amp(value, **options):
+        try:
+            amp_x = options['amp_x']
+        except KeyError:
+            amp_x = 1
+        return value * amp_x
+    assert amp(1, amp_x=5) == 5
+    assert amp(2.0, amp_x=5) == 10.0