fix: Remove float() coercion in Python loops (#6259)

Coercion to a float is a very JavaScript thing to do, Python is not JavaScript.

From this discussion:
https://groups.google.com/g/blockly/c/OF_j9rKQgpI
This commit is contained in:
Neil Fraser
2022-07-06 08:46:10 -07:00
committed by GitHub
parent aaafbc2b6f
commit 5612e13824
2 changed files with 15 additions and 18 deletions

View File

@@ -134,14 +134,11 @@ def ${Python.FUNCTION_NAME_PLACEHOLDER_}(start, stop, step):
if (stringUtils.isNumber(arg)) {
// Simple number.
arg = Number(arg);
} else if (arg.match(/^\w+$/)) {
// Variable.
arg = 'float(' + arg + ')';
} else {
// It's complicated.
} else if (!arg.match(/^\w+$/)) {
// Not a variable, it's complicated.
const varName = Python.nameDB_.getDistinctName(
variable0 + suffix, NameType.VARIABLE);
code += varName + ' = float(' + arg + ')\n';
code += varName + ' = ' + arg + '\n';
arg = varName;
}
return arg;