Skip to content

Commit 7ac088d

Browse files
committed
Remove support for annotated partials
1 parent dd34efc commit 7ac088d

File tree

2 files changed

+1
-34
lines changed

2 files changed

+1
-34
lines changed

marshmallow_dataclass/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,6 @@ def _field_for_annotated_type(
755755
is_generic_type(arg)
756756
and _is_marshmallow_field(typing_extensions.get_origin(arg))
757757
)
758-
# Support `partial(mf.List, mf.String)`
759-
or (isinstance(arg, partial) and _is_marshmallow_field(arg.func))
760758
]
761759
if marshmallow_annotations:
762760
if len(marshmallow_annotations) > 1:

tests/test_annotated.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import dataclasses
2-
import functools
31
import sys
42
import unittest
5-
from typing import List, Optional
3+
from typing import Optional
64

75
import marshmallow
86
import marshmallow.fields
@@ -37,32 +35,3 @@ class AnnotatedValue:
3735

3836
with self.assertRaises(marshmallow.exceptions.ValidationError):
3937
schema.load({"value": "notavalidemail"})
40-
41-
def test_annotated_partial_field(self) -> None:
42-
"""
43-
NewType allowed us to specify a lambda or partial because there was no type inspection.
44-
But with Annotated we do type inspection. Partial still allows us to to type inspection.
45-
"""
46-
47-
@dataclass
48-
class AnnotatedValue:
49-
emails: Annotated[
50-
List[str],
51-
functools.partial(marshmallow.fields.List, marshmallow.fields.Email),
52-
] = dataclasses.field(default_factory=lambda: ["default@email.com"])
53-
54-
schema = AnnotatedValue.Schema() # type: ignore[attr-defined]
55-
56-
self.assertEqual(
57-
schema.load({}),
58-
AnnotatedValue(emails=["default@email.com"]),
59-
)
60-
self.assertEqual(
61-
schema.load({"emails": ["test@test.com"]}),
62-
AnnotatedValue(
63-
emails=["test@test.com"],
64-
),
65-
)
66-
67-
with self.assertRaises(marshmallow.exceptions.ValidationError):
68-
schema.load({"emails": "notavalidemail"})

0 commit comments

Comments
 (0)