diff --git a/pydantic/schema.py b/pydantic/schema.py index 80e5dc7396d..fb98af898d1 100644 --- a/pydantic/schema.py +++ b/pydantic/schema.py @@ -638,8 +638,11 @@ def field_singleton_sub_fields_schema( def safe_issubclass(a: Any, b: Any) -> bool: - # `typing.Pattern` is not a valid type - return issubclass(a, b) if a is not Pattern else (a is b) + """If `a` is not a valid class (e.g. `typing.Pattern`), `issubclass` works only if `a is b`""" + try: + return issubclass(a, b) + except TypeError: + return False def add_field_type_to_schema(field_type: Any, schema: Dict[str, Any]) -> None: