Skip to content

Commit 3e1a051

Browse files
author
Joel Collins
committed
Tidied up
1 parent e01dff8 commit 3e1a051

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

labthings/server/view/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def __init__(self, *args, **kwargs):
2828

2929
def get_value(self):
3030
get_method = getattr(self, "get", None) # Look for this views GET method
31-
if callable(get_method): # Check it's callable
32-
response = get_method() # pylint: disable=not-callable
31+
if get_method is None:
32+
return None
33+
if not callable(get_method):
34+
raise TypeError("Attribute 'get' of View must be a callable")
35+
response = get_method() # pylint: disable=not-callable
3336
if isinstance(response, ResponseBase): # Pluck useful data out of HTTP response
3437
return response.json if response.json else response.data.decode()
3538
else: # Unless somehow an HTTP response isn't returned...
@@ -43,8 +46,8 @@ def dispatch_request(self, *args, **kwargs):
4346
if meth is None and request.method == "HEAD":
4447
meth = getattr(self, "get", None)
4548

46-
if meth is None:
47-
raise MethodNotAllowed(f"Unimplemented method {request.method}")
49+
# Flask should ensure this is assersion never fails
50+
assert meth is not None, f"Unimplemented method {request.method!r}"
4851

4952
# Generate basic response
5053
resp = meth(*args, **kwargs)

0 commit comments

Comments
 (0)