touilleMan / godot-python

Python support for Godot 🐍🐍🐍
Other
1.85k stars 140 forks source link

Optional arguments appearing as positional arguments #27

Open williamd1k0 opened 7 years ago

williamd1k0 commented 7 years ago

I don't know if I'm doing something wrong but all Godot methods that contain optional arguments are being called as if all arguments were positional.

Eg: Node.add_child( Node node, bool legible_unique_name=false )

The node argument is positional but legible_unique_name is optional.

So, calling this by passing only node argument triggers a TypeError.

Python traceback:

Traceback (most recent call last):
  File "<init code for 'pythonscriptcffi'>", line 131, in pybind_call_meth
  File "/home/williamd1k0/Downloads/godot-python-0.9.0/examples/AngryMark/SimpleTest.py", line 22, in _input
    self.add_child(grr)
  File "<init code for 'pythonscriptcffi'>", line 3409, in bind
TypeError: add_child() takes 2 positional argument but 1 were given

Also, I'm using your release v0.9.0 for Linux.

touilleMan commented 7 years ago

Yes, optional arguments are not handled right now

However this can be implemented fairly easy: a bind function is generated for each method of a Godot node.

Right now the bind method only take a *args parameter and use a dictionary given by meth['args'] to make sure the types and right. You can add a **kwargs and test it against meth['args'] items in the same way.

If you need help, you go in the Godot's Discord channel, I hang there pretty often ;-)

williamd1k0 commented 7 years ago

I took a look at the bind stuff but I don't know how to check/get the default values for optional methods. There is a default_args key in the meth dict but it always appears as empty (probably not implemented yet).