From 6ecbf1b576a679a4328c087c3a1c05fd7fbcc44c Mon Sep 17 00:00:00 2001 From: Toby Harradine Date: Fri, 26 Nov 2021 10:00:16 +1100 Subject: [PATCH] Allow None when Any or object is in Union Resolves #3444 --- pydantic/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydantic/fields.py b/pydantic/fields.py index a15d0ab583..6eed85e4b7 100644 --- a/pydantic/fields.py +++ b/pydantic/fields.py @@ -563,10 +563,11 @@ def _type_analysis(self) -> None: # noqa: C901 (ignore complexity) if is_union_origin(origin): types_ = [] for type_ in get_args(self.type_): - if type_ is NoneType: + if type_ is NoneType or type_ is Any or type_ is object: if self.required is Undefined: self.required = False self.allow_none = True + if type_ is NoneType: continue types_.append(type_)