From 236ac4eab57bbfde556d388db4134dc5da16b49d Mon Sep 17 00:00:00 2001 From: Evan Hubinger Date: Tue, 21 Mar 2017 16:50:38 -0700 Subject: [PATCH] Adds stargs and kwargs support to methodcaller partial Refs #228. --- coconut/compiler/grammar.py | 2 +- tests/src/cocotest/agnostic/suite.coco | 3 ++- tests/src/cocotest/agnostic/util.coco | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/coconut/compiler/grammar.py b/coconut/compiler/grammar.py index 51e71bafc..06f373bb3 100644 --- a/coconut/compiler/grammar.py +++ b/coconut/compiler/grammar.py @@ -703,7 +703,7 @@ class Grammar(object): questionmark | dubstar + test | star + test | name + default | test ), comma)) methodcaller_args = ( - itemlist(condense(name + default | test), comma) + itemlist(condense(dubstar + test | star + test | name + default | test), comma) | op_item ) diff --git a/tests/src/cocotest/agnostic/suite.coco b/tests/src/cocotest/agnostic/suite.coco index 6481b23f5..fab448f87 100644 --- a/tests/src/cocotest/agnostic/suite.coco +++ b/tests/src/cocotest/agnostic/suite.coco @@ -288,5 +288,6 @@ def suite_test(): assert Tuple(1, 2, 3) != Tuple(1, 2) assert map(plus1, (1, 2, 3)) |> fmap$(times2) |> repr == map(times2..plus1, (1, 2, 3)) |> repr assert reversed((1, 2, 3)) |> fmap$(plus1) |> repr == map(plus1, (1, 2, 3)) |> reversed |> repr - assert identity_getitem()[1:2, 2:3] == (slice(1, 2), slice(2, 3)) == identity_getitem() |> .[1:2, 2:3] + assert ident[1:2, 2:3] == (slice(1, 2), slice(2, 3)) == ident |> .[1:2, 2:3] + assert ident.method(*(1,), **{"a": 2}) == ((1,), {"a": 1}) == ident |> .method(*(1,), **{"a": 2}) return True diff --git a/tests/src/cocotest/agnostic/util.coco b/tests/src/cocotest/agnostic/util.coco index 98e02677c..d3b67726a 100644 --- a/tests/src/cocotest/agnostic/util.coco +++ b/tests/src/cocotest/agnostic/util.coco @@ -575,8 +575,10 @@ def ret_none(n): def ret_args_kwargs(*args, **kwargs) = (args, kwargs) -class identity_getitem: +class identity_operations: def __getitem__(self, *args) = args + def method(self, *args, **kwargs) = (args, kwargs) +ident = identity_operations() # Typing