Inline-Python
Inline-Python copied to clipboard
Unnecessary/harmful itemization of arrays as hash elements
Marshalling Python objects to Perl 6 introduces an unnecessary and harmful level of itemization of arrays inside hashes/dicts, as demonstrated by this code:
use v6;
use Inline::Python;
use json:from<Python>;
.say for json::loads('["a", "b"]'); # two iterations, as expected
.say for json::loads('{ "x": ["a", "b"] }')<x>; # just one iteration
say json::loads('{ "x": ["a", "b"] }').perl; # {:x($["a", "b"])}
I do have a fix, but I'm not sure what the right behavior would actually be. Both Inline::Perl5 and pure Perl 6 behave just the same:
perl6 -e 'dd EVAL q/{a => [1, 2]}/, :lang<Perl5>;' ${:a($[1, 2])} perl6 -e 'dd EVAL q/{a => [1, 2]}/;' Hash % = {:a($[1, 2])} perl6 -e 'dd {a => [1, 2]};' Hash % = {:a($[1, 2])}
oh, good point, I hadn't realized that. You're probably right that this should stay as it is.
There's still something weird going on in the other direct, passing arrays to python function (they seem to get flattened out, due to the use *@args instead of **@args), but I guess that's a topic for another issue.