@@ -166,7 +166,7 @@ def add_schema(_cls=None, base_schema=None):
166
166
This decorator adds a marshmallow schema as the 'Schema' attribute in a dataclass.
167
167
It uses :func:`class_schema` internally.
168
168
169
- :param type cls : The dataclass to which a Schema should be added
169
+ :param type _cls : The dataclass to which a Schema should be added
170
170
:param base_schema: marshmallow schema used as a base class when deriving dataclass schema
171
171
172
172
>>> class BaseSchema(marshmallow.Schema):
@@ -183,6 +183,7 @@ def add_schema(_cls=None, base_schema=None):
183
183
"""
184
184
185
185
def decorator (clazz : Type [_U ]) -> Type [_U ]:
186
+ # noinspection PyTypeHints
186
187
clazz .Schema = class_schema (clazz , base_schema ) # type: ignore
187
188
return clazz
188
189
@@ -304,7 +305,7 @@ def class_schema(
304
305
305
306
@lru_cache (maxsize = MAX_CLASS_SCHEMA_CACHE_SIZE )
306
307
def _internal_class_schema (
307
- clazz : type , base_schema : Optional [Type [marshmallow .Schema ]] = None
308
+ clazz : type , base_schema : Optional [Type [marshmallow .Schema ]] = None
308
309
) -> Type [marshmallow .Schema ]:
309
310
try :
310
311
# noinspection PyDataclass
@@ -313,12 +314,13 @@ def _internal_class_schema(
313
314
try :
314
315
warnings .warn (
315
316
f"marshmallow_dataclass was called on the class { clazz } , which is not a dataclass. "
316
- f"It is going to try and convert the class into a dataclass, which may have undesirable side effects. "
317
- f"To avoid this message, make sure all your classes and all the classes of their fields are either "
318
- f"explicitly supported by marshmallow_datcalass, or are already dataclasses. "
319
- f"For more information, see https://github.com/lovasoa/marshmallow_dataclass/issues/51" ,
317
+ f"It is going to try and convert the class into a dataclass, which may have "
318
+ f"undesirable side effects. To avoid this message, make sure all your classes and "
319
+ f"all the classes of their fields are either explicitly supported by "
320
+ f"marshmallow_datcalass, or are already dataclasses. For more information, see "
321
+ f"https://github.com/lovasoa/marshmallow_dataclass/issues/51"
320
322
)
321
- created_dataclass = dataclasses .dataclass (clazz )
323
+ created_dataclass : type = dataclasses .dataclass (clazz )
322
324
return _internal_class_schema (created_dataclass , base_schema )
323
325
except Exception :
324
326
raise TypeError (
@@ -521,7 +523,7 @@ def field_for_schema(
521
523
# Nested dataclasses
522
524
forward_reference = getattr (typ , "__forward_arg__" , None )
523
525
nested = (
524
- nested_schema or forward_reference or _internal_class_schema (typ , base_schema )
526
+ nested_schema or forward_reference or _internal_class_schema (typ , base_schema )
525
527
)
526
528
527
529
return marshmallow .fields .Nested (nested , ** metadata )
@@ -604,8 +606,11 @@ def new_type(x: _U):
604
606
return x
605
607
606
608
new_type .__name__ = name
609
+ # noinspection PyTypeHints
607
610
new_type .__supertype__ = typ # type: ignore
611
+ # noinspection PyTypeHints
608
612
new_type ._marshmallow_field = field # type: ignore
613
+ # noinspection PyTypeHints
609
614
new_type ._marshmallow_args = kwargs # type: ignore
610
615
return new_type
611
616
0 commit comments