From daed3c9f69cfdef83f1d37de7482ec266c22c44b Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Mon, 20 Jan 2020 16:26:29 +0000 Subject: [PATCH] Blackened --- examples/properties_dictionary.py | 10 +++------- labthings/core/utilities.py | 5 ++++- labthings/server/decorators.py | 4 +++- labthings/server/types.py | 7 +++++-- labthings/server/views/docs/__init__.py | 12 +++++++++--- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/examples/properties_dictionary.py b/examples/properties_dictionary.py index c8de1110..6abf0dc7 100644 --- a/examples/properties_dictionary.py +++ b/examples/properties_dictionary.py @@ -1,10 +1,7 @@ from fractions import Fraction from labthings.server.quick import create_app -from labthings.server.decorators import ( - ThingProperty, - PropertySchema, -) +from labthings.server.decorators import ThingProperty, PropertySchema from labthings.server.view import View from labthings.server.find import find_component from labthings.server.types import data_dict_to_schema @@ -29,9 +26,7 @@ def __init__(self): self.some_property = Fraction(5, 2) self.some_string = "Hello" - self.prop_keys = [ - "magic_denoise", "some_property", "some_string", "x_range" - ] + self.prop_keys = ["magic_denoise", "some_property", "some_string", "x_range"] def get_state(self): return {key: getattr(self, key) for key in self.prop_keys} @@ -46,6 +41,7 @@ def get_state_schema(self): s = data_dict_to_schema(self.get_state()) return s + my_component = MyComponent() diff --git a/labthings/core/utilities.py b/labthings/core/utilities.py index 31f4aa71..9169cca4 100644 --- a/labthings/core/utilities.py +++ b/labthings/core/utilities.py @@ -56,7 +56,10 @@ def rapply(data, func, apply_to_iterables=True): # If the object is a dictionary if isinstance(data, collections.abc.Mapping): - return {key: rapply(val, func, apply_to_iterables=apply_to_iterables) for key, val in data.items()} + return { + key: rapply(val, func, apply_to_iterables=apply_to_iterables) + for key, val in data.items() + } # If the object is iterable but NOT a dictionary or a string elif apply_to_iterables and ( isinstance(data, collections.abc.Iterable) diff --git a/labthings/server/decorators.py b/labthings/server/decorators.py index c9b2c073..199a699f 100644 --- a/labthings/server/decorators.py +++ b/labthings/server/decorators.py @@ -48,7 +48,9 @@ def __init__(self, schema, code=200): elif isinstance(self.schema, Schema): self.converter = self.schema.jsonify else: - raise TypeError(f"Unsupported schema type {type(self.schema)} for marshal_with") + raise TypeError( + f"Unsupported schema type {type(self.schema)} for marshal_with" + ) def __call__(self, f): # Pass params to call function attribute for external access diff --git a/labthings/server/types.py b/labthings/server/types.py index 42e973fa..c5c46499 100644 --- a/labthings/server/types.py +++ b/labthings/server/types.py @@ -71,7 +71,9 @@ def make_primative(value): global DEFAULT_BUILTIN_CONVERSIONS, DEFAULT_TYPE_MAPPING logging.debug(f"Converting {value} to primative type...") - value_typestrings = [x.__module__+"."+x.__name__ for x in inspect.getmro(type(value))] + value_typestrings = [ + x.__module__ + "." + x.__name__ for x in inspect.getmro(type(value)) + ] for typestring in value_typestrings: if typestring in DEFAULT_BUILTIN_CONVERSIONS: @@ -108,6 +110,7 @@ def data_dict_to_schema(data_dict): return working_dict + # TODO: Deserialiser with inverse defaults # TODO: Option to switch to .npy serialisation/deserialisation (or look for a better common array format) @@ -126,4 +129,4 @@ def data_dict_to_schema(data_dict): "val4": range(1, 5) } -""" \ No newline at end of file +""" diff --git a/labthings/server/views/docs/__init__.py b/labthings/server/views/docs/__init__.py index 4d2def8d..f6d1172d 100644 --- a/labthings/server/views/docs/__init__.py +++ b/labthings/server/views/docs/__init__.py @@ -60,15 +60,21 @@ def get(self): if hasattr(prop, "get") and not ( hasattr(prop, "post") or hasattr(prop, "put") ): - prop_schema = convert_schema(get_spec(prop.get).get("_schema").get(200), swag) + prop_schema = convert_schema( + get_spec(prop.get).get("_schema").get(200), swag + ) # If prop is write-only elif not hasattr(prop, "get") and ( hasattr(prop, "post") or hasattr(prop, "put") ): if hasattr(prop, "post"): - prop_schema = convert_schema(get_spec(prop.post).get("_params"), swag) + prop_schema = convert_schema( + get_spec(prop.post).get("_params"), swag + ) elif hasattr(prop, "put"): - prop_schema = convert_schema(get_spec(prop.put).get("_params"), swag) + prop_schema = convert_schema( + get_spec(prop.put).get("_params"), swag + ) else: prop_schema = {}