Skip to content

Commit 459c5f3

Browse files
authored
Merge pull request #59 from labthings/deepsource-fix-bc989c9b
Fix dangerous default argument
2 parents a465bcf + 7dbed81 commit 459c5f3

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

examples/components/pdf_component.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def data(self):
4040
"""Return a 1D data trace."""
4141
return [self.noisy_pdf(x) for x in self.x_range]
4242

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

4749
for i in range(n):

labthings/server/labthing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ def __init__(
3636
prefix: str = "",
3737
title: str = "",
3838
description: str = "",
39-
types: list = [],
39+
types: list = None,
4040
version: str = "0.0.0",
4141
format_flask_exceptions: bool = True,
4242
):
43+
if types is None:
44+
types = []
4345
self.app = app # Becomes a Flask app
4446
self.sockets = None # Becomes a Socket(app) websocket handler
4547

labthings/server/quick.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def create_app(
1010
prefix: str = "",
1111
title: str = "",
1212
description: str = "",
13-
types: list = [],
13+
types: list = None,
1414
version: str = "0.0.0",
1515
handle_errors: bool = True,
1616
handle_cors: bool = True,
@@ -33,6 +33,8 @@ def create_app(
3333
Returns:
3434
(Flask app object, LabThings object)
3535
"""
36+
if types is None:
37+
types = []
3638
# Handle arguments
3739
if flask_kwargs is None:
3840
flask_kwargs = {}

tests/test_server_quick.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ def test_create_app():
1212

1313
def test_create_app_options():
1414
app, labthing = quick.create_app(
15-
__name__, flask_kwargs={"static_url_path": "/static"}, handle_cors=False
15+
__name__,
16+
types=["org.labthings.tests.labthing"],
17+
flask_kwargs={"static_url_path": "/static"},
18+
handle_cors=False,
1619
)
1720
assert isinstance(app, Flask)
1821
assert isinstance(labthing, LabThing)

tests/test_server_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ def test_function_signature_to_schema():
8686
from marshmallow import Schema
8787

8888
def test_func(
89-
positional: int, n: int = 10, optlist: List[int] = [1, 2, 3], untyped="untyped"
89+
positional: int, n: int = 10, optlist: List[int] = None, untyped="untyped"
9090
):
91+
if optlist is None:
92+
optlist = [1, 2, 3]
9193
pass
9294

9395
gen_schema_dict = types.function_signature_to_schema(test_func)

0 commit comments

Comments
 (0)