Repository: pydantic/pydantic

Issue:
Pydantic "Not Recognizing" Field in BaseModel with Default Value of Type
### 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

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
pydantic version: 1.7.3
pydantic compiled: True
python version: 3.8.2 (default, Mar 13 2020, 10:14:16)  [GCC 9.3.0]
platform: Linux-4.19.128-microsoft-standard-x86_64-with-glibc2.29
optional deps. installed: ['typing-extensions']
```


```py
import pydantic
from typing import Type, Sequence, Union

class T:
    pass

class Model(pydantic.BaseModel):
    t: Union[Type[T], Sequence[Type[T]]] = T
    
    @pydantic.validator("t", always=True)
    def make_tuple(cls, v):
        if isinstance(v, Sequence):
            return tuple(v)
        return v,

# ConfigError: Validators defined with incorrect fields: make_tuple (use check_fields=False if you're inheriting from the model and intended this)
```

**_Note:_** If the field is marked optional and the default value is set to `None`, the code works without issue.

```py
import pydantic
from typing import Type, Sequence, Union, Optional

class T:
    pass

class Model(pydantic.BaseModel):
    t: Optional[Union[Type[T], Sequence[Type[T]]]] = None
    
    @pydantic.validator("t", always=True)
    def make_tuple(cls, v):
        if not v:
            return T,
        elif isinstance(v, Sequence):
            return tuple(v)
        return v,

Model()
# Model(t=(<class '__main__.T'>,))
```

Perhaps I am missing something obvious in my sleep-deprived stupor?


Comments:

Patch:
diff --git a/pydantic/main.py b/pydantic/main.py
--- a/pydantic/main.py
+++ b/pydantic/main.py
@@ -34,7 +34,15 @@
 from .parse import Protocol, load_file, load_str_bytes
 from .schema import default_ref_template, model_schema
 from .types import PyObject, StrBytes
-from .typing import AnyCallable, ForwardRef, get_origin, is_classvar, resolve_annotations, update_field_forward_refs
+from .typing import (
+    AnyCallable,
+    ForwardRef,
+    get_args,
+    get_origin,
+    is_classvar,
+    resolve_annotations,
+    update_field_forward_refs,
+)
 from .utils import (
     ROOT_KEY,
     ClassAttribute,
@@ -253,10 +261,13 @@ def __new__(mcs, name, bases, namespace, **kwargs):  # noqa C901
                 elif is_valid_field(ann_name):
                     validate_field_name(bases, ann_name)
                     value = namespace.get(ann_name, Undefined)
+                    allowed_types = get_args(ann_type) if get_origin(ann_type) is Union else (ann_type,)
                     if (
                         isinstance(value, untouched_types)
                         and ann_type != PyObject
-                        and not lenient_issubclass(get_origin(ann_type), Type)
+                        and not any(
+                            lenient_issubclass(get_origin(allowed_type), Type) for allowed_type in allowed_types
+                        )
                     ):
                         continue
                     fields[ann_name] = inferred = ModelField.infer(


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
@@ -2,7 +2,7 @@
 from collections.abc import Hashable
 from decimal import Decimal
 from enum import Enum
-from typing import Any, Dict, FrozenSet, Generic, List, Optional, Set, Tuple, Type, TypeVar, Union
+from typing import Any, Dict, FrozenSet, Generic, List, Optional, Sequence, Set, Tuple, Type, TypeVar, Union
 
 import pytest
 
@@ -1122,8 +1122,11 @@ class Model(BaseModel):
         d: FooBar = FooBar
         e: Type[FooBar]
         f: Type[FooBar] = FooBar
+        g: Sequence[Type[FooBar]] = [FooBar]
+        h: Union[Type[FooBar], Sequence[Type[FooBar]]] = FooBar
+        i: Union[Type[FooBar], Sequence[Type[FooBar]]] = [FooBar]
 
-    assert Model.__fields__.keys() == {'b', 'c', 'e', 'f'}
+    assert Model.__fields__.keys() == {'b', 'c', 'e', 'f', 'g', 'h', 'i'}
 
 
 def test_assign_type():