Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Inline/Python.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,10 @@ method create_subclass(Str $package, Str $class, Str $subclass_name) {
.map({" def {$_.gist}(self, *args): return perl6.invoke(self.__p6_index__, '{$_.gist}', args)"})\
.join("\n");
my $baseclass_name = $package eq '__main__' ?? $class !! "$package.$class";
my $final_subclass_name = $subclass_name;
$final_subclass_name ~~ s:g{'::'} = '__';
self.run(qq:heredoc/PYTHON/ ~ $methods, :file);
class {$subclass_name}($baseclass_name):
class {$final_subclass_name}($baseclass_name):
def __init__(self, i, *args):
if i is not None:
self.__set_p6_index__(i)
Expand All @@ -459,7 +461,9 @@ method create_parent_object(Str $package, Str $class, PythonParent $obj) returns
my $tuple = py_tuple_new(1);
my $index = $objects.keep($obj);
py_tuple_set_item($tuple, 0, self.p6_to_py($index));
my $parent = py_call_function($package, $class, $tuple);
my $final_class = $class;
$final_class ~~ s:g{'::'} = '__';
my $parent = py_call_function($package, $final_class, $tuple);
self.handle_python_exception();
return self.py_to_p6($parent);
}
Expand Down
11 changes: 10 additions & 1 deletion t/inherit.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use v6;
use Inline::Python;
use Test;

plan 8;
plan 9;

my $py = Inline::Python.new();

Expand Down Expand Up @@ -61,6 +61,15 @@ class Qux does Inline::Python::PythonParent['__main__', 'PyBar'] {

is((Qux.new().test)(), 'Perl6!!');

class My::Qux does Inline::Python::PythonParent['__main__', 'PyBar'] {
method qux() {
return "Perl6!!";
}

}

is((My::Qux.new().test)(), 'Perl6!!');

# Test passing a Py object to the constructor of a P6 subclass

class Perl6ObjectCreator {
Expand Down