Skip to content

Commit 6ef3f4a

Browse files
author
Joel Collins
committed
Fixed view schema type annotations
1 parent 53e077c commit 6ef3f4a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/labthings/views/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
from collections import OrderedDict
3-
from typing import Dict, List, Optional, Set
3+
from typing import Union, Dict, List, Optional, Set
44

55
from flask import request
66
from flask.views import MethodView
@@ -12,11 +12,15 @@
1212
from ..marshalling import marshal_with, use_args
1313
from ..representations import DEFAULT_REPRESENTATIONS
1414
from ..schema import ActionSchema, EventSchema, Schema, build_action_schema
15+
from ..fields import Field
1516
from ..utilities import unpack
1617
from . import builder, op
1718

1819
__all__ = ["MethodView", "View", "ActionView", "PropertyView", "op", "builder"]
1920

21+
# Type alias for convenience
22+
OptionalSchema = Optional[Union[Schema, Dict[str, Field]]]
23+
2024

2125
class View(MethodView):
2226
"""A LabThing Resource class should make use of functions
@@ -108,8 +112,8 @@ class ActionView(View):
108112
""" """
109113

110114
# Data formatting
111-
schema: Optional[Schema] = None # Schema for Action response
112-
args: Optional[dict] = None # Schema for input arguments
115+
schema: OptionalSchema = None # Schema for Action response
116+
args: OptionalSchema = None # Schema for input arguments
113117
semtype: Optional[str] = None # Semantic type string
114118

115119
# Spec overrides
@@ -205,7 +209,7 @@ class PropertyView(View):
205209
""" """
206210

207211
# Data formatting
208-
schema: Optional[Schema] = None # Schema for input AND output
212+
schema: OptionalSchema = None # Schema for input AND output
209213
semtype: Optional[str] = None # Semantic type string
210214

211215
# Spec overrides
@@ -245,7 +249,7 @@ class EventView(View):
245249
""" """
246250

247251
# Data formatting
248-
schema: Optional[Schema] = None # Schema for Event data
252+
schema: OptionalSchema = None # Schema for Event data
249253
semtype: Optional[str] = None # Semantic type string
250254

251255
# Spec overrides

0 commit comments

Comments
 (0)