Skip to content

Commit

Permalink
Support named arguments in wrappers for imported Python packages
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Mar 5, 2017
1 parent 5a18fc7 commit 71bd44d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Inline/Python.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ method import(Str $name) {
my $value = py_getattr($py_module, $attr_name);
if py_callable_check($value) {
# create wrapper function in package
$class.WHO{"&$attr_name"} := sub (*@args) {
self.call($name, $attr_name, @args.list);
$class.WHO{"&$attr_name"} := sub (*@args, *%args) {
self.call($name, $attr_name, |@args, |%args);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions named.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from logging import warn
def test_named(a, b):
return a + b
def test_kwargs(**kwargs):
return len(kwargs)
7 changes: 7 additions & 0 deletions t/import.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ use string:from<Python>;
my $py = Inline::Python.default_python;
is(string::capwords('foo bar'), 'Foo Bar');

#use sys:from<Python>;
#BEGIN sys::path::append('t/pylib');

use named:from<Python>;
is named::test_named(a => 1, b => 2), 3;
is named::test_kwargs(a => 1, b => 2), 2;

done-testing;

0 comments on commit 71bd44d

Please sign in to comment.