Skip to content

Commit

Permalink
Added newline to the end of Python types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaoticz committed Feb 10, 2024
1 parent ee90aad commit 25bca96
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 8 deletions.
4 changes: 0 additions & 4 deletions Json2SharpLib/Emitters/Python/PythonClassEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public string Parse(string objectName, JsonElement jsonElement)
if (--_stackCounter == default && _addTypeHint && stringBuilder.Contains("Optional["))
stringBuilder.Insert(0, "from typing import Optional" + Environment.NewLine + Environment.NewLine + Environment.NewLine);

// Remove the last newline
if (_stackCounter == default)
stringBuilder.Remove(stringBuilder.Length - Environment.NewLine.Length, Environment.NewLine.Length);

return stringBuilder.ToStringAndClear();
}

Expand Down
4 changes: 0 additions & 4 deletions Json2SharpLib/Emitters/Python/PythonDataClassEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public string Parse(string objectName, JsonElement jsonElement)
stringBuilder.Insert(0, "from typing import Optional" + Environment.NewLine);
}

// Remove the last newline
if (_stackCounter == default)
stringBuilder.Remove(stringBuilder.Length - Environment.NewLine.Length, Environment.NewLine.Length);

return stringBuilder.ToStringAndClear();
}

Expand Down
3 changes: 3 additions & 0 deletions Json2SharpTests/PythonTests/Models/Answers/ArrayTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ArrayTypes:
nullable_mixed_array: Optional[list[object]]
thing_array: list[ThingArray]
nullable_thing_array: list[Optional[NullableThingArray]]
""";

public const string Output = """
Expand Down Expand Up @@ -91,6 +92,7 @@ def __init__(
self.nullable_mixed_array = nullable_mixed_array
self.thing_array = thing_array
self.nullable_thing_array = nullable_thing_array
""";

public const string OutputNoTypeHints = """
Expand Down Expand Up @@ -133,5 +135,6 @@ def __init__(
self.nullable_mixed_array = nullable_mixed_array
self.thing_array = thing_array
self.nullable_thing_array = nullable_thing_array
""";
}
3 changes: 3 additions & 0 deletions Json2SharpTests/PythonTests/Models/Answers/BoolTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from dataclasses import dataclass
class BoolTypes:
true_bool: bool
false_bool: bool
""";

public const string Output = """
Expand All @@ -27,6 +28,7 @@ def __init__(
) -> None:
self.true_bool = true_bool
self.false_bool = false_bool
""";

public const string OutputNoTypeHints = """
Expand All @@ -37,5 +39,6 @@ def __init__(
):
self.true_bool = true_bool
self.false_bool = false_bool
""";
}
3 changes: 3 additions & 0 deletions Json2SharpTests/PythonTests/Models/Answers/FloatTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FloatTypes:
float_number: float
double_number: float
decimal_number: float
""";

public const string Output = """
Expand All @@ -31,6 +32,7 @@ def __init__(
self.float_number = float_number
self.double_number = double_number
self.decimal_number = decimal_number
""";

public const string OutputNoTypeHints = """
Expand All @@ -43,5 +45,6 @@ def __init__(
self.float_number = float_number
self.double_number = double_number
self.decimal_number = decimal_number
""";
}
3 changes: 3 additions & 0 deletions Json2SharpTests/PythonTests/Models/Answers/IntegerTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class IntegerTypes:
uint_number: int
long_number: int
ulong_number: int
""";

public const string Output = """
Expand All @@ -35,6 +36,7 @@ def __init__(
self.uint_number = uint_number
self.long_number = long_number
self.ulong_number = ulong_number
""";

public const string OutputNoTypeHints = """
Expand All @@ -49,5 +51,6 @@ def __init__(
self.uint_number = uint_number
self.long_number = long_number
self.ulong_number = ulong_number
""";
}
3 changes: 3 additions & 0 deletions Json2SharpTests/PythonTests/Models/Answers/ObjectTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ObjectTypes:
null_thing: Optional[object]
empty_thing: object
thing: Thing
""";

public const string Output = """
Expand All @@ -57,6 +58,7 @@ def __init__(
self.null_thing = null_thing
self.empty_thing = empty_thing
self.thing = thing
""";

public const string OutputNoTypeHints = """
Expand All @@ -80,5 +82,6 @@ def __init__(
self.null_thing = null_thing
self.empty_thing = empty_thing
self.thing = thing
""";
}
3 changes: 3 additions & 0 deletions Json2SharpTests/PythonTests/Models/Answers/TextTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from dataclasses import dataclass
class TextTypes:
text: str
empty_text: str
""";

public const string Output = """
Expand All @@ -27,6 +28,7 @@ def __init__(
) -> None:
self.text = text
self.empty_text = empty_text
""";

public const string OutputNoTypeHints = """
Expand All @@ -37,5 +39,6 @@ def __init__(
):
self.text = text
self.empty_text = empty_text
""";
}

0 comments on commit 25bca96

Please sign in to comment.