niner / inline-python-pm

Inline::Python - Write Perl subs and classes in Python.
https://metacpan.org/release/Inline-Python
20 stars 13 forks source link

Pass ASCII strings as <class 'str'> in Python 3 #28

Closed s-nez closed 4 years ago

s-nez commented 4 years ago

ASCII strings are not flagged as utf8 by default, however since ASCII-only strings are encoded in exactly the same way before and after utf8::upgrade, it's safe to decode them. This allows most regular Perl strings to be properly passed as str to Python 3 (non-ASCII strings will have the utf8 flag on under the utf8 pragma, others will still be passed as bytes).

This fixes #27 .

marekro commented 4 years ago

I tested this with Python 3.6.3a and Perl 5.26.1 - all internal tests passing, and works just fine with a bunch of extra Python packages. A strong +1 to include this in an official Inline::Python release!

niner commented 4 years ago

I actually use a similar heuristic in Inline::Perl5, giving me great confidence that this works well in practice.

Thanks for the PR!