Skip to content

Commit 99a24f6

Browse files
authored
Strip function body of CodeInput (#92)
This removes the linebreak at the end which results in undesired formatting in the `CodeInput`.
1 parent a8a21d0 commit 99a24f6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/scwidgets/code/_widget_code_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def get_function_body(function: types.FunctionType) -> str:
251251
line[leading_indent:] if line.strip() else "" for line in lines
252252
)
253253

254-
return source
254+
return source.strip()
255255

256256
@property
257257
def function(self) -> types.FunctionType:

tests/test_code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ def test_get_docstring(self):
8585
def test_get_function_body(self):
8686
assert (
8787
CodeInput.get_function_body(self.mock_function_1)
88-
== "if x > 0:\n return x + y\nelse:\n return y + z()\n"
88+
== "if x > 0:\n return x + y\nelse:\n return y + z()"
8989
)
90-
assert CodeInput.get_function_body(self.mock_function_2) == "return x\n"
91-
assert CodeInput.get_function_body(self.mock_function_3) == "return x\n"
90+
assert CodeInput.get_function_body(self.mock_function_2) == "return x"
91+
assert CodeInput.get_function_body(self.mock_function_3) == "return x"
9292
assert (
9393
CodeInput.get_function_body(self.mock_function_4)
94-
== "return x # noqa: E702\n"
94+
== "return x # noqa: E702"
9595
)
9696
assert (
9797
CodeInput.get_function_body(self.mock_function_5)
98-
== "def x():\n return 5\nreturn x()\n"
98+
== "def x():\n return 5\nreturn x()"
9999
)
100-
assert CodeInput.get_function_body(self.mock_function_6) == "return x\n"
100+
assert CodeInput.get_function_body(self.mock_function_6) == "return x"
101101
with pytest.raises(
102102
ValueError,
103103
match=r"Did not find any def definition. .*",

0 commit comments

Comments
 (0)