pythonizer icon indicating copy to clipboard operation
pythonizer copied to clipboard

Incorrect code for shift/pop of an empty array

Open snoopyjc opened this issue 3 years ago • 1 comments

In perl, a shift/pop on an empty list returns undef. The python generated code raises an exception. Example for optional arguments:

$thresh = shift;
$thresh = 1000
    unless defined $thresh;

Fix is to generate:

thresh=perl_arg_array.pop(0) if perl_arg_array else None
if not (thresh != None):
   thresh=1000    

snoopyjc avatar Nov 12 '21 05:11 snoopyjc

Fixed in https://github.com/snoopyjc/pythonizer

snoopyjc avatar Feb 07 '22 16:02 snoopyjc