What's wrong
PythonGenerator.PythonTypeName (Coder/Languages/PythonGenerator.cs ~line 695) maps only int, string, bool, float, double and void. Every other type name is written through unchanged. The C, C++, Go and Rust type maps all translate long (to long long, int64 and i64), and C# accepts long natively. Python has no long. Parameter and return annotations are evaluated when the def runs, and no from __future__ import annotations is emitted, so the generated module fails as soon as it is imported.
This is distinct from #102, which covers annotations naming a class that is declared later.
Repro
var f = new FunctionDeclaration("total") { ReturnType = "long" };
f.Parameters.Add(new Parameter("count", "long"));
f.Body.Add(new ReturnStatement(new VariableReference("count")));
var file = new SourceFile("m"); file.Members.Add(f);
Console.WriteLine(new PythonGenerator().Generate(file));
- Actual:
def total(count: long) -> long:. python3 -c "import m" fails with NameError: name 'long' is not defined.
- Expected:
def total(count: int) -> int:.
Suggested fix
Add "long" => "int" to PythonTypeName. It is worth checking the other numeric names the other generators map (e.g. short, byte, decimal) at the same time. Add a case to PythonGeneratedSourceImportsTests that imports a module using long.
What's wrong
PythonGenerator.PythonTypeName(Coder/Languages/PythonGenerator.cs~line 695) maps onlyint,string,bool,float,doubleandvoid. Every other type name is written through unchanged. The C, C++, Go and Rust type maps all translatelong(tolong long,int64andi64), and C# acceptslongnatively. Python has nolong. Parameter and return annotations are evaluated when thedefruns, and nofrom __future__ import annotationsis emitted, so the generated module fails as soon as it is imported.This is distinct from #102, which covers annotations naming a class that is declared later.
Repro
def total(count: long) -> long:.python3 -c "import m"fails withNameError: name 'long' is not defined.def total(count: int) -> int:.Suggested fix
Add
"long" => "int"toPythonTypeName. It is worth checking the other numeric names the other generators map (e.g.short,byte,decimal) at the same time. Add a case toPythonGeneratedSourceImportsTeststhat imports a module usinglong.