Skip to content

Commit dc7547a

Browse files
author
Joel Collins
committed
MyPy fixes
1 parent bc6b70b commit dc7547a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/labthings/schema.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
"pre_load",
1717
"pre_dump",
1818
"validate",
19+
"FuzzySchemaType"
1920
]
2021

21-
22+
# Type alias for a Schema, Field, or Dict of Fields or Types
23+
FuzzySchemaType = Union[Schema, fields.Field, Dict[str, Union[fields.Field, type]]]
2224
class FieldSchema(Schema):
2325
""" "Virtual schema" for handling individual fields treated as schemas.
2426
@@ -132,8 +134,8 @@ def generate_links(self, data, **_):
132134

133135

134136
def build_action_schema(
135-
output_schema: Optional[Union[Schema, Dict]],
136-
input_schema: Optional[Union[Schema, Dict]],
137+
output_schema: Optional[FuzzySchemaType],
138+
input_schema: Optional[FuzzySchemaType],
137139
name: Optional[str] = None,
138140
):
139141
"""Builds a complete schema for a given ActionView. That is, it reads any input and output
@@ -151,7 +153,7 @@ def build_action_schema(
151153
if not name.endswith("Action"):
152154
name = f"{name}Action"
153155

154-
class_attrs = {}
156+
class_attrs: Dict[str, Union[fields.Nested, fields.Field]] = {}
155157

156158
for key, schema in {"output": output_schema, "input": input_schema}.items():
157159
# If no schema is given, move on

src/labthings/views/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
from ..find import current_labthing, find_extension
1212
from ..marshalling import marshal_with, use_args
1313
from ..representations import DEFAULT_REPRESENTATIONS
14-
from ..schema import ActionSchema, EventSchema, Schema, build_action_schema
14+
from ..schema import ActionSchema, EventSchema, Schema, FuzzySchemaType, build_action_schema
1515
from ..fields import Field
1616
from ..utilities import unpack
1717
from . import builder, op
1818

1919
__all__ = ["MethodView", "View", "ActionView", "PropertyView", "op", "builder"]
2020

2121
# Type alias for convenience
22-
OptionalSchema = Optional[Union[Schema, Field, Dict[str, Field]]]
22+
OptionalSchema = Optional[FuzzySchemaType]
2323

2424

2525
class View(MethodView):

0 commit comments

Comments
 (0)