Cannot return a Python `datetime.date` object through Inline::Python
I can't seem to return any Python datetime.date objects, they all come
back as Any. This is what I've tried:
use v6;
use Inline::Python;
my $py = Inline::Python.new;
$py.run('import datetime');
say $py.call('datetime', 'date', 2017, 1, 1)
And I also tried this:
use Inline::Python;
say Inline::Python.new.run("from datetime import date\ndate(2017, 1, 1)");
say Inline::Python.new.run("from datetime import datetime\ndatetime(2017, 1, 1, 0, 0, 0)");
They all come out as Any. I think this is a bug in Inline::Python.
Well it is a bug in Inline::Python as it does not correctly handle this type but.....boy does Python make the job hard. Those date objects are no ordinary Python objects. The datetime "module" is built into the Python interpreter itself and written completely in C. PyObject_IsInstance returns false on them which is why Inline::Python does not just wrap them. There is apparently a PyDate_Check function especially for recognizing date objects.
I seem to be able to call methods on python date objects just fine:
use Inline::Python;
my $py = Inline::Python.new;
$py.run('import datetime');
my $date = $py.call('datetime', 'date', 2017, 1, 31);
say $date.isoformat().decode;
so I wouldn't object to you closing this issue, @niner :-)