godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

Can't concatenate GDString and str

Open matheus2740 opened this issue 5 years ago • 2 comments

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")

matheus2740 avatar May 26 '20 22:05 matheus2740

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 ;-)

touilleMan avatar May 28 '20 11:05 touilleMan

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 :)

matheus2740 avatar May 28 '20 18:05 matheus2740