Repository: pydantic/pydantic

Issue:
"none is not an allowed value" when using Union with Any
### Checks

* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug

# Bug
It seems that `None` is allowed when a field's type is `Any` (as is expected, stated in the docs), but `None` is not allowed when a field's type is `Union[SomeType, Any]`.

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
             pydantic version: 1.8.2
            pydantic compiled: True
                 install path: C:\Users\TobyHarradine\PycharmProjects\orchestration\.venv\Lib\site-packages\pydantic
               python version: 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]
                     platform: Windows-10-10.0.19041-SP0
     optional deps. installed: ['typing-extensions']
```

Code which reproduces the issue:
```pycon
>>> import pydantic
>>> class M(pydantic.BaseModel):
...     a: Any
...
>>> M(a=1)
M(a=1)
>>> M(a=None)
M(a=None)
>>> class M(pydantic.BaseModel):
...     a: Union[int, Any]
...
>>> M(a=1)
M(a=1)
>>> M(a="abcd")
M(a='abcd')
>>> M(a=None)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "pydantic\main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for M
a
  none is not an allowed value (type=type_error.none.not_allowed)

```

This may be somewhat related to #1624.


Discussion:
`allow_none` attribute for field `a` remains `False`. Possible fix may be in pydantic/fields.py:566:
```
if is_union_origin(origin):
    types_ = []
    for type_ in get_args(self.type_):
        if type_ is NoneType or type_ is Any or type_ is object:
            if self.required is Undefined:
                self.required = False
            self.allow_none = True
            continue
        types_.append(type_)
```
@mykhailoleskiv That almost works, except it doesn't add `Any` or `object` to `types_` (which eventually becomes `ModelField.sub_fields`). So `M(a="abcd")` or something like that no longer works. I'll open a PR

Resolving patch:
diff --git a/pydantic/fields.py b/pydantic/fields.py
--- a/pydantic/fields.py
+++ b/pydantic/fields.py
@@ -34,7 +34,6 @@
     Callable,
     ForwardRef,
     NoArgAnyCallable,
-    NoneType,
     display_as_type,
     get_args,
     get_origin,
@@ -563,10 +562,11 @@ def _type_analysis(self) -> None:  # noqa: C901 (ignore complexity)
         if is_union(origin):
             types_ = []
             for type_ in get_args(self.type_):
-                if type_ is NoneType:
+                if is_none_type(type_) or type_ is Any or type_ is object:
                     if self.required is Undefined:
                         self.required = False
                     self.allow_none = True
+                if is_none_type(type_):
                     continue
                 types_.append(type_)
 


Test patch:
diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py
--- a/tests/test_edge_cases.py
+++ b/tests/test_edge_cases.py
@@ -83,6 +83,23 @@ class Model(BaseModel):
     ]
 
 
+def test_union_int_any():
+    class Model(BaseModel):
+        v: Union[int, Any]
+
+    m = Model(v=123)
+    assert m.v == 123
+
+    m = Model(v='123')
+    assert m.v == 123
+
+    m = Model(v='foobar')
+    assert m.v == 'foobar'
+
+    m = Model(v=None)
+    assert m.v is None
+
+
 def test_union_priority():
     class ModelOne(BaseModel):
         v: Union[int, str] = ...