Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/components/pdf_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def data(self):
"""Return a 1D data trace."""
return [self.noisy_pdf(x) for x in self.x_range]

def average_data(self, n: int = 10, optlist: List[int] = [1, 2, 3]):
def average_data(self, n: int = 10, optlist: List[int] = None):
"""Average n-sets of data. Emulates a measurement that may take a while."""
if optlist is None:
optlist = [1, 2, 3]
summed_data = self.data

for i in range(n):
Expand Down
4 changes: 3 additions & 1 deletion labthings/server/labthing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def __init__(
prefix: str = "",
title: str = "",
description: str = "",
types: list = [],
types: list = None,
version: str = "0.0.0",
format_flask_exceptions: bool = True,
):
if types is None:
types = []
self.app = app # Becomes a Flask app
self.sockets = None # Becomes a Socket(app) websocket handler

Expand Down
4 changes: 3 additions & 1 deletion labthings/server/quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_app(
prefix: str = "",
title: str = "",
description: str = "",
types: list = [],
types: list = None,
version: str = "0.0.0",
handle_errors: bool = True,
handle_cors: bool = True,
Expand All @@ -34,6 +34,8 @@ def create_app(
Returns:
(Flask app object, LabThings object)
"""
if types is None:
types = []
# Handle arguments
if flask_kwargs is None:
flask_kwargs = {}
Expand Down
5 changes: 4 additions & 1 deletion tests/test_server_quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def test_create_app():

def test_create_app_options():
app, labthing = quick.create_app(
__name__, flask_kwargs={"static_url_path": "/static"}, handle_cors=False
__name__,
types=["org.labthings.tests.labthing"],
flask_kwargs={"static_url_path": "/static"},
handle_cors=False,
)
assert isinstance(app, Flask)
assert isinstance(labthing, LabThing)
4 changes: 3 additions & 1 deletion tests/test_server_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ def test_function_signature_to_schema():
from marshmallow import Schema

def test_func(
positional: int, n: int = 10, optlist: List[int] = [1, 2, 3], untyped="untyped"
positional: int, n: int = 10, optlist: List[int] = None, untyped="untyped"
):
if optlist is None:
optlist = [1, 2, 3]
pass

gen_schema_dict = types.function_signature_to_schema(test_func)
Expand Down