# Buggy code
def find_validators(
    type_: AnyType, arbitrary_types_allowed: bool = False
) -> List[AnyCallable]:
    if type_ is Any or type(type_) == ForwardRef:
        return []
    if type_ is Pattern:
        return pattern_validators
    if is_callable_type(type_):
        return [callable_validator]

    supertype = _find_supertype(type_)
    if supertype is not None:
        type_ = supertype

    for val_type, validators in _VALIDATORS:
        try:
            if issubclass(type_, val_type):
                return validators
        except TypeError as e:
            raise RuntimeError(
                f"error checking inheritance of {type_!r} (type: {display_as_type(type_)})"
            ) from e

    if arbitrary_types_allowed:
        return [make_arbitrary_type_validator(type_)]
    else:
        raise RuntimeError(f"no validator found for {type_}")


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/validators.py in find_validators(type_, arbitrary_types_allowed)
385         try:
--> 386             if issubclass(type_, val_type):
387                 return validators

TypeError: issubclass() arg 1 must be a class

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-c7b931439a60> in <module>
----> 1 class Subclass(BaseModel):
2     asdf: int
3     fdsa: Dict

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/main.py in __new__(mcs, name, bases, namespace)
180                     annotation=ann_type,
181                     class_validators=vg.get_validators(ann_name),
--> 182                     config=config,
183                 )
184

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in infer(cls, name, value, annotation, class_validators, config)
136             required=required,
137             model_config=config,
--> 138             schema=schema,
139         )
140

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in __init__(self, name, type_, class_validators, model_config, default, required, alias, schema)
105         self.parse_json: bool = False
106         self.shape: Shape = Shape.SINGLETON
--> 107         self.prepare()
108
109     @classmethod

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in prepare(self)
170             self.allow_none = True
171
--> 172         self._populate_sub_fields()
173         self._populate_validators()
174

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in _populate_sub_fields(self)
221             assert issubclass(origin, Mapping)
222             self.key_field = self._create_sub_type(
--> 223                 self.type_.__args__[0], 'key_' + self.name, for_keys=True  # type: ignore
224             )
225             self.type_ = self.type_.__args__[1]  # type: ignore

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in _create_sub_type(self, type_, name, for_keys)
235             name=name,
236             class_validators=None if for_keys else {k: v for k, v in self.class_validators.items() if not v.whole},
--> 237             model_config=self.model_config,
238         )
239

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in __init__(self, name, type_, class_validators, model_config, default, required, alias, schema)
105         self.parse_json: bool = False
106         self.shape: Shape = Shape.SINGLETON
--> 107         self.prepare()
108
109     @classmethod

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in prepare(self)
171
172         self._populate_sub_fields()
--> 173         self._populate_validators()
174
175     def _populate_sub_fields(self) -> None:  # noqa: C901 (ignore complexity)

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/fields.py in _populate_validators(self)
253                     get_validators()
254                     if get_validators
--> 255                     else find_validators(self.type_, self.model_config.arbitrary_types_allowed)
256                 ),
257                 self.schema is not None and self.schema.const and constant_validator,

/scratch/miniconda3/envs/jupyter/lib/python3.7/site-packages/pydantic/validators.py in find_validators(type_, arbitrary_types_allowed)
387                 return validators
388         except TypeError as e:
--> 389             raise RuntimeError(f'error checking inheritance of {type_!r} (type: {display_as_type(type_)})') from e
390
391     if arbitrary_types_allowed:

RuntimeError: error checking inheritance of ~KT (type: KT)

# Fixed code
def find_validators(
    type_: AnyType, arbitrary_types_allowed: bool = False
) -> List[AnyCallable]:
    if type_ is Any or type(type_) in (ForwardRef, TypeVar):
        return []
    if type_ is Pattern:
        return pattern_validators
    if is_callable_type(type_):
        return [callable_validator]

    supertype = _find_supertype(type_)
    if supertype is not None:
        type_ = supertype

    for val_type, validators in _VALIDATORS:
        try:
            if issubclass(type_, val_type):
                return validators
        except TypeError as e:
            raise RuntimeError(
                f"error checking inheritance of {type_!r} (type: {display_as_type(type_)})"
            ) from e

    if arbitrary_types_allowed:
        return [make_arbitrary_type_validator(type_)]
    else:
        raise RuntimeError(f"no validator found for {type_}")