Skip to content

Commit daed3c9

Browse files
author
Joel Collins
committed
Blackened
1 parent f00ddf3 commit daed3c9

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

examples/properties_dictionary.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from fractions import Fraction
22

33
from labthings.server.quick import create_app
4-
from labthings.server.decorators import (
5-
ThingProperty,
6-
PropertySchema,
7-
)
4+
from labthings.server.decorators import ThingProperty, PropertySchema
85
from labthings.server.view import View
96
from labthings.server.find import find_component
107
from labthings.server.types import data_dict_to_schema
@@ -29,9 +26,7 @@ def __init__(self):
2926
self.some_property = Fraction(5, 2)
3027
self.some_string = "Hello"
3128

32-
self.prop_keys = [
33-
"magic_denoise", "some_property", "some_string", "x_range"
34-
]
29+
self.prop_keys = ["magic_denoise", "some_property", "some_string", "x_range"]
3530

3631
def get_state(self):
3732
return {key: getattr(self, key) for key in self.prop_keys}
@@ -46,6 +41,7 @@ def get_state_schema(self):
4641
s = data_dict_to_schema(self.get_state())
4742
return s
4843

44+
4945
my_component = MyComponent()
5046

5147

labthings/core/utilities.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def rapply(data, func, apply_to_iterables=True):
5656

5757
# If the object is a dictionary
5858
if isinstance(data, collections.abc.Mapping):
59-
return {key: rapply(val, func, apply_to_iterables=apply_to_iterables) for key, val in data.items()}
59+
return {
60+
key: rapply(val, func, apply_to_iterables=apply_to_iterables)
61+
for key, val in data.items()
62+
}
6063
# If the object is iterable but NOT a dictionary or a string
6164
elif apply_to_iterables and (
6265
isinstance(data, collections.abc.Iterable)

labthings/server/decorators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def __init__(self, schema, code=200):
4848
elif isinstance(self.schema, Schema):
4949
self.converter = self.schema.jsonify
5050
else:
51-
raise TypeError(f"Unsupported schema type {type(self.schema)} for marshal_with")
51+
raise TypeError(
52+
f"Unsupported schema type {type(self.schema)} for marshal_with"
53+
)
5254

5355
def __call__(self, f):
5456
# Pass params to call function attribute for external access

labthings/server/types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def make_primative(value):
7171
global DEFAULT_BUILTIN_CONVERSIONS, DEFAULT_TYPE_MAPPING
7272

7373
logging.debug(f"Converting {value} to primative type...")
74-
value_typestrings = [x.__module__+"."+x.__name__ for x in inspect.getmro(type(value))]
74+
value_typestrings = [
75+
x.__module__ + "." + x.__name__ for x in inspect.getmro(type(value))
76+
]
7577

7678
for typestring in value_typestrings:
7779
if typestring in DEFAULT_BUILTIN_CONVERSIONS:
@@ -108,6 +110,7 @@ def data_dict_to_schema(data_dict):
108110

109111
return working_dict
110112

113+
111114
# TODO: Deserialiser with inverse defaults
112115
# TODO: Option to switch to .npy serialisation/deserialisation (or look for a better common array format)
113116

@@ -126,4 +129,4 @@ def data_dict_to_schema(data_dict):
126129
"val4": range(1, 5)
127130
}
128131
129-
"""
132+
"""

labthings/server/views/docs/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ def get(self):
6060
if hasattr(prop, "get") and not (
6161
hasattr(prop, "post") or hasattr(prop, "put")
6262
):
63-
prop_schema = convert_schema(get_spec(prop.get).get("_schema").get(200), swag)
63+
prop_schema = convert_schema(
64+
get_spec(prop.get).get("_schema").get(200), swag
65+
)
6466
# If prop is write-only
6567
elif not hasattr(prop, "get") and (
6668
hasattr(prop, "post") or hasattr(prop, "put")
6769
):
6870
if hasattr(prop, "post"):
69-
prop_schema = convert_schema(get_spec(prop.post).get("_params"), swag)
71+
prop_schema = convert_schema(
72+
get_spec(prop.post).get("_params"), swag
73+
)
7074
elif hasattr(prop, "put"):
71-
prop_schema = convert_schema(get_spec(prop.put).get("_params"), swag)
75+
prop_schema = convert_schema(
76+
get_spec(prop.put).get("_params"), swag
77+
)
7278
else:
7379
prop_schema = {}
7480

0 commit comments

Comments
 (0)