Repository: justanr/marshmallow-annotations

Issue:
Register default Dictionary[TKey, TValue] converter
Probably similar looking to the default List converter.

Discussion:

Patch:
diff --git a/docs/quickstart.rst b/docs/quickstart.rst
index c174015..6ab35ef 100644
--- a/docs/quickstart.rst
+++ b/docs/quickstart.rst
@@ -149,6 +149,12 @@ types mapped to marshmallow fields, these fields and their mappings are:
 - :class:`~datetime.time` maps to :class:`~marshmallow.fields.Time`
 - :class:`~datetime.timedelta` maps to :class:`~marshmallow.fields.TimeDelta`
 - :class:`~uuid.UUID` maps to :class:`~marshmallow.fields.UUID`
+- :class:`dict` maps to :class:`~marshmallow.fields.Dict`
+
+
+.. note::
+
+    See below for details on the ``dict`` mapping.
 
 
 List[T]
@@ -188,6 +194,17 @@ it generates the base fieldi but will default ``required`` to False and
         Union[int, float, None]
 
 
+Dict[TKey, TValue]
+==================
+
+``marshmallow-annotations`` does support handling automatic conversions for
+:class:`dict` mapped fields. However, ``marshmallow`` itself does not provide
+additional serialization and deserialization support for dictionary fields, so
+even if a field is mapped as ``Dict[int, string]`` the output of that field
+will be the raw input. If you require dictionary serialization, you may
+consider using a custom field.
+
+
 Forward Declaration
 ===================
 
diff --git a/src/marshmallow_annotations/registry.py b/src/marshmallow_annotations/registry.py
index 9a4d9db..67ed3fc 100644
--- a/src/marshmallow_annotations/registry.py
+++ b/src/marshmallow_annotations/registry.py
@@ -73,6 +73,7 @@ class DefaultTypeRegistry(TypeRegistry):
     - time -> fields.Time
     - timedelta -> fields.TimeDelta
     - UUID -> fields.UUID
+    - dict -> fields.Dict
 
     As well as a special factory for typing.List[T] that will generate either
     fields.List or fields.Nested
@@ -91,6 +92,8 @@ class DefaultTypeRegistry(TypeRegistry):
             time: fields.Time,
             timedelta: fields.TimeDelta,
             UUID: fields.UUID,
+            dict: fields.Dict,
+            Dict: fields.Dict,
         }.items()
     }
 


Test patch:
diff --git a/test/test_converter.py b/test/test_converter.py
index 2486b04..241f58d 100644
--- a/test/test_converter.py
+++ b/test/test_converter.py
@@ -96,3 +96,13 @@ def test_override_missing(registry_):
     assert generated_fields["id"].missing == missing
     assert generated_fields["name"].missing == "a"
     assert generated_fields["points"].missing == list
+
+
+def test_can_convert_Dict_type_to_DictField(registry_):
+    class HasDictField:
+        mapping: typing.Dict[int, str]
+
+    converter = BaseConverter(registry=registry_)
+    generated_fields = converter.convert_all(HasDictField)
+
+    assert isinstance(generated_fields["mapping"], fields.Dict)