-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove convert()
utility method
#66116
Conversation
PLEASE don't remove the convert function, i need it too! |
I see some opposition. What are the weird edge cases and why is it unsafe? |
It is unsafe, because you can put any type (or just any integer) as the second argument, but the conversion might be unsupported. The function doesn't provide type hint and may result in an error. As for edge-cases, I referred to the use-case of this function. It's just very niche and if you need it, you can use That said, I'm ok if the function is kept, but then we need to properly fix the linked issues somehow. |
I have a feeling if we the contributor of the engine can't do write a correct convert function correctly in the engine. We can't expect the user-developers of Godot Engine to do it correctly either. |
Eh but GDScript implementation looks like this func convert(variant, type):
match type:
TYPE_INT:
return variant as int
TYPE_FLOAT
return variant as float
etc. The C++ implementation just uses some convoluted built-in logic, so it's more difficult to get right. |
The fact that |
I see it the same way, having a convert method makes perfect sense. |
For my uses, I want a loose conversion. I opened #70080 to accomplish this. I think that it would be a good idea to remove this old utility method and replace it with the superior method I propose in #70080. It uses the same logic as the internal Variant operators, so it is able to easily convert many things to many other things. |
Also against removing this. Its not unsafe because it ensures you get the type no matter the input. If you want the safe version, you just use a cast. |
This method simply calls the constructor of the target type. It might be useful e.g. if you want to pass the type as parameter to have some generic conversion function, but it's some weird edge case and it's unsafe. You can achieve the same using a series of ifs..
Closes #5523
Closes #65919