touilleMan / godot-python

Python support for Godot 🐍🐍🐍
Other
1.88k stars 143 forks source link

Can't concatenate GDString and str #188

Open matheus2740 opened 4 years ago

matheus2740 commented 4 years ago
Traceback (most recent call last):
  File "build/osx-64/pythonscript/_godot_instance.pxi", line 98, in _godot.pythonscript_instance_call_method
  File "/Volumes/OSX_BAK_S/salvia/gdproj/fork/godot-python/tests/repl/addons/pythonscript_repl/PythonREPL.py", line 22, in execute
    cmd = ">>> " + string
TypeError: Argument 'self' has incorrect type (expected godot.builtins.GDString, got str)

Code:

string = self.input_box.get_text()
cmd = ">>> " + string

self.input_box is of type LineEdit, acquired via self.get_node("InputBox")

touilleMan commented 4 years ago

Explicit conversion between GDString and python str is intended. The idea is to be aware of the place those conversion appear given they should be much more costly than regular python str to str operations.

Of course I'm open to discuss this if can draw a good rational ;-)

matheus2740 commented 4 years ago

IMO automatic conversion would be better, especially for new users who might not understand the difference (of course one could argue that such users should be using GDScript instead of python, but anyway...) I understand conversion is costly, but I don't think string operations are common enough to be a performance penalty (if user wants to do heavy string processing in the game loop they most probably know what they are doing anyway.) In either case that's a design decision and up to you :)