Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
change dep to taylors branch
  • Loading branch information
agoscinski committed Feb 17, 2025
1 parent 44495c4 commit 5ecd803
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
dependencies = [
"ipywidgets>=8.0.0",
"numpy<2.0.0",
"widget_code_input>=4.0.13",
"widget_code_input @ git+https://github.com/agoscinski/widget-code-input.git@flexi-docstring",
"matplotlib",
"termcolor"
]
Expand Down
11 changes: 7 additions & 4 deletions src/scwidgets/code/_widget_code_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import types
import warnings
from functools import wraps
from typing import Any, List, Optional, Tuple
from typing import Any, List, Optional, Tuple, Union

from widget_code_input import WidgetCodeInput
from widget_code_input.utils import (
Expand Down Expand Up @@ -71,7 +71,6 @@ def __init__(
if function_name is None:
raise ValueError("function_name must be given if no function is given.")
function_parameters = "" if function_parameters is None else function_parameters
docstring = "\n" if docstring is None else docstring
function_body = "" if function_body is None else function_body
self._builtins = {} if builtins is None else builtins
super().__init__(
Expand Down Expand Up @@ -152,9 +151,13 @@ def function_parameters_name(self) -> List[str]:
return self.function_parameters.replace(",", "").split(" ")

@staticmethod
def get_docstring(function: types.FunctionType) -> str:
def get_docstring(function: types.FunctionType) -> Union[str, None]:
docstring = function.__doc__
return "" if docstring is None else textwrap.dedent(docstring)
return (
None
if docstring is None
else textwrap.dedent(docstring).strip('"""') # noqa: B005
)

@staticmethod
def _get_function_source_and_def(
Expand Down
1 change: 1 addition & 0 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_get_function_paramaters(self):
assert CodeInput.get_function_parameters(self.mock_function_7) == "x, **kwargs"

def test_get_docstring(self):
assert CodeInput.get_docstring(self.mock_function_0) is None
assert (
CodeInput.get_docstring(self.mock_function_1)
== "\nThis is an example function.\nIt adds two numbers.\n"
Expand Down

0 comments on commit 5ecd803

Please sign in to comment.