SolidCode/SolidPython

Fail due to (not really) missing positional arguments

rockstorm101 opened this issue · 2 comments

The following SCAD file works just fine and generates a cube as expected:

// my_module.scad

my_cube(arg3 = 5);

module my_cube(arg1, arg2, arg3)
{
    s = arg3
         ? arg3 * 2
         : arg2
             ? arg2 / 2
             : arg1;
    cube([s,s,s]);
}

However, importing such file into SolidPython and attempting the same result, i.e. the code below:

# test.py

import solid as sp

my_module = sp.import_scad('./my_module.scad')

def my_function():
    return my_module.my_cube(arg3 = 5)

if __name__ == '__main__':
    sp.scad_render_to_file(my_function(), include_orig_code = False)

Fails with the following error:

$ python test.py 
Traceback (most recent call last):
  File "/tmp/test/test.py", line 11, in <module>
    sp.scad_render_to_file(my_function(), include_orig_code = False)
  File "/tmp/test/test.py", line 8, in my_function
    return my_module.my_cube(arg3 = 5)
TypeError: __init__() missing 2 required positional arguments: 'arg1' and 'arg2'

Redefining my_function in test.py as per below to explicitly set 'arg1' and 'arg2' as 'None':

def my_function():
    return my_module.my_cube(None, None, arg3 = 5)

Produces the SCAD code I was expecting:

use </tmp/test/my_module.scad>

my_cube(arg3 = 5);

Happy to help debug/test further if required.

System Info:

  • SolidPython 1.0.5
  • Python 3.9.1+
  • Debian Sid

Fixed & tested in fa26086. Thanks for including the test case; that made it really easy to confirm the fix