Skip to content

Commit 4317055

Browse files
authored
Remove usages of typing.Type to fix compatibility with Python<3.5.3 (#1410)
* Remove usages of typing.Type to fix compatibility with Python<3.5.3 * Update changelog
1 parent bff3166 commit 4317055

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Features:
88

99
- Add type annotations to ``marshmallow.schema`` and ``marshmallow.validate`` (:pr:`1407`, :issue:`663`).
1010

11+
Bug fixes:
12+
13+
- Fix compatibility with Python < 3.5.3 (:issue:`1409`). Thanks :user:`lukaszdudek-silvair` for reporting.
14+
1115
Refactoring:
1216

1317
- Remove unnecessary ``BaseSchema`` superclass (:pr:`1406`).

src/marshmallow/fields.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ class Nested(Field):
471471

472472
def __init__(
473473
self,
474-
nested: typing.Union[SchemaABC, typing.Type[SchemaABC], str],
474+
nested: typing.Union[SchemaABC, type, str],
475475
*,
476476
default: typing.Any = missing_,
477477
only: types.StrSequenceOrSet = None,
@@ -664,9 +664,7 @@ class List(Field):
664664

665665
default_error_messages = {"invalid": "Not a valid list."}
666666

667-
def __init__(
668-
self, cls_or_instance: typing.Union[Field, typing.Type[Field]], **kwargs
669-
):
667+
def __init__(self, cls_or_instance: typing.Union[Field, type], **kwargs):
670668
super().__init__(**kwargs)
671669
try:
672670
self.inner = resolve_field_instance(cls_or_instance)
@@ -1427,8 +1425,8 @@ class Mapping(Field):
14271425

14281426
def __init__(
14291427
self,
1430-
keys: typing.Union[Field, typing.Type[Field]] = None,
1431-
values: typing.Union[Field, typing.Type[Field]] = None,
1428+
keys: typing.Union[Field, type] = None,
1429+
values: typing.Union[Field, type] = None,
14321430
**kwargs
14331431
):
14341432
super().__init__(**kwargs)

src/marshmallow/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ def set_class(self) -> type:
415415
@classmethod
416416
def from_dict(
417417
cls,
418-
fields: typing.Dict[str, typing.Union[ma_fields.Field, typing.Type]],
418+
fields: typing.Dict[str, typing.Union[ma_fields.Field, type]],
419419
*,
420420
name: str = "GeneratedSchema"
421-
) -> typing.Type["Schema"]:
421+
) -> type:
422422
"""Generate a `Schema` class given a dictionary of fields.
423423
424424
.. code-block:: python

0 commit comments

Comments
 (0)